for example.. number.txt: (has these contents)
my source code is..

#include <stdio.h>
int main()
 FILE *infile;
 double a, b, c;
 char d;
 double sum;
 infile = fopen("number.txt", "r");
 if(infile == NULL)
  printf("number DOES NOT EXISTS!");
  while(!foef(infile)) /*here's my problem*/
  fscanf(infile, "%lf%c%lf%c%lf\n", &a,&d,&b,&d,&c); /*fscanf is used*/
  printf("%f %f %f", a, b, c); /*just for checking*/
  sum = a + b + c;
  printf("sum is %f", sum);
return 0;

problem is..

if i put the while loop, it won't compile. it has these error message saying "undefined reference to `foef'".
if i remove the while loop, the fscanf reads only the first line.
i would like to read also the other data from line 2 and line 3 and solve their sum respectively.
so how can i loop the the fscanf?(assuming that i don't know how many lines are in the file? or maybe its safe to say to loop the fscanf until EOF?)
thanks a lot!

Recommended Answers

All 3 Replies

>while(!foef(infile)) /*here's my problem*/
Try !feof(infile)

Aia and OP, try this... ;)

Aia and OP, try this... ;)

Live and learn, I'm glad you took the time to post this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.