I'm attempting to write a program that will (in part) read data from three different .txt files into three different structures, so they can be used to determine the states of various appliances. Initially I wrote a version of the code that used a single file and it worked fine, the problem is trying to add options to the code.
I have the code to read the file:
void ReadDataFile(char *location) {
int t=0, k;
char src[100]={};
strcat( strcat(src, MYPATH), location);
ptr = fopen(src,"r");
if(ptr == NULL)
{
printf("Error!\n");
exit(1);
}
printf("Success!\n");
From here I'm trying to use if statements to determine where data is stored. An example of the first one is:
if(location == "living_room.txt") {
printf("Filepath found!\n");
while ((!feof(ptr)) && (t<24)) {
//read time
fscanf(ptr, "%s", &(*ptr2)[t].LR.hour);
//read temperatures
fscanf(ptr, "%f%f", &(*ptr2)[t].LR.eTemp, &(*ptr2)[t].LR.iTemp);
//read humidity
fscanf(ptr, "%f", &(*ptr2)[t].LR.hum);
//read motion data
for ( k=0; k<6; k++)
fscanf(ptr,"%f", &(*ptr2)[t].LR.mot[k]);
t++;
} }
I can't figure out what should be in the arguments for the if statement (if this is a sensible approach).
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire