Hi all,
Printable View
Hi all,
I need to process data from a file with the following format:
All I really need is the three last numbers. I need to read them, and process them until the end of the file.Code:41.877430 0.200000 0.200000 1.000000 1
42.339146 0.200000 0.200000 0.400000 1
42.507645 1.000000 1.000000 0.400000 1
43.607258 0.500000 0.500000 0.200000 1
I tried the following program:
But it does not work. In particular, I am not sure how to read the numbers, how to start a new line, and how to know when I reach the end of the file.Code:FILE *infile;
int main(void)
{float sim_time, p, q, s,sum;
int accepted;
infile = fopen("temp_log", "w");
while(!feof(infile)) {
/* loop through and store the numbers into the array */
fscanf(infile, "%f %f %f %f %i", &sim_time, &p, &q, &s, &accepted);
sum += complex_function(q,s,accepted);
}
printf("The sum is %f \n" ,sum);
fclose(infile);
}
Thanks for any ideas.
Tor