A
A
Alexander Rybakov2018-11-01 22:01:12
C++ / C#
Alexander Rybakov, 2018-11-01 22:01:12

Doesn't read from a file?

In general, there is a .txt file with the following content:

oleg gil 22 33
zina fuu 23 32
zoya sup 35 21
filya kirya 40 42
pentu pep 25 34

and there is part of the code:
file = fopen("edb.txt", "r");
i = 0;
while (fscanf(file, "%s%s%d%d", &A[i].firstName, &A[i].secondName, &(A[i].age), &(A[i].weight)) != EOF) {
fscanf(file, "%s%s%d%d", &A[i].firstName, &A[i].secondName, &(A[i].age), &(A[i].weight));
printf("%s%s%d%d\n", (A[i].firstName), (A[i].secondName), (A[i].age), (A[i].weight));
N++;
i++;
}

And here's what it produces:
yeAxsln04-E.jpg
Question: why doesn't it put all the values ​​that are given in the source file into the array of structures????

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-11-01
@GavriKos

Well, as if you have two fscanfs written to one i-th element of the array - one in the while condition, the second immediately below.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question