English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

for example.. number.txt: (has these contents)

1.75:2.00:3.00
2.00:5.00:7.24
3.00:6.35:1.00

--
my source code is..

#include
int main()
{
FILE *infile;
double a, b, c, sum;
char d;

infile = fopen("number.txt", "r");
if(infile == NULL)
{
printf("number DOES NOT EXISTS!");
}
else
{
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);
}

}
fclose(infile);
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!

2007-03-22 04:32:44 · 5 answers · asked by Anonymous in Computers & Internet Programming & Design

5 answers

try feof
it is not foef

2007-03-22 04:38:00 · answer #1 · answered by abd 5 · 0 0

For the best answers, search on this site https://shorturl.im/au09Q

The only time k increments is if character is = to a comma. So you read the character, set k = 0 then enter your loop. If character is not a comma then k never increments, which means it stays in the loop, since it uses the SAME character instead of reading the next character.

2016-04-01 20:15:24 · answer #2 · answered by Anonymous · 0 0

This Site Might Help You.

RE:
how do you loop fscanf until EOF in c?
for example.. number.txt: (has these contents)

1.75:2.00:3.00
2.00:5.00:7.24
3.00:6.35:1.00

--
my source code is..

#include <stdio.h>
int main()
{
FILE *infile;
double a, b, c, sum;
char d;

infile = fopen("number.txt", "r");
if(infile ==...

2015-08-06 04:29:34 · answer #3 · answered by Anonymous · 0 0

Do this:

while (fscanf(infile, "%lf%c%lf%c%lf\n", &a,&d,&b,&d,&c) ){
.
.
.
}

fscanf should return false if it runs out of data

2007-03-22 04:46:12 · answer #4 · answered by Amanda H 6 · 0 0

are you serious man ?

2014-11-05 04:33:42 · answer #5 · answered by Steve Red 1 · 0 0

fedest.com, questions and answers