I'm using fscanf in a text file like this:
T 1 1000
T 2 700
N 3 450
Y 4 200
I'm trying to count the lines to use a malloc and to do that I use:
Prize temp;
int count =0;
while ((fscanf(fa,"%c %d %f", &temp.A, &temp.B, &temp.C))!= EOF)
count ++;
where Prize is a struct:
typedef struct {
char A;
int B;
float C;
} Prize;
So, after reading the lines the program prints me this:
A: T B: 1 C: 1000.0000
A: B: 0 C: 0.0000
A: T B: 2 C: 700.0000
A: B: 0 C: 0.0000
A: N B: 3 C: 450.0000
A: B: 0 C: 0.0000
A: Y B: 4 C: 200.0000
Using the debugger I noticed that fscanf
gets (for example while reading the first line):
A = 84 'T', B=1, C=1000
and instead of reading the second line it reads another first line, but like this:
A = 10'\n', B=1, C=1000
and continues doing this for each line but the last.
I controlled the file and it doesn't have extra spaces or lines.
Any suggestions to solve the problem?