-2
Apparently it follows everything right in the recording inside the while, I put a printf to test, but after the loop, I did not print the vector items anymore, and I could not find the error:
#include <stdio.h>
typedef struct date
{
char nome[15];
int tam;
} date;
int main(void)
{
FILE *arq;
date dados[5];
int i=0;
arq = fopen("App.txt", "r");
if(arq == NULL)
{
printf("Erro, nao foi possivel abrir o arquivo\n");
}
else
{
while( (fscanf(arq, "%s %d\n", dados[i].nome, &dados[i].tam)) != EOF )
{
printf("%s %d \n", dados[i].nome, dados[i].tam);
i++;
}
}
printf("%s %d \n", dados[0].nome, dados[0].tam); //Nao imprimi
fclose(arq);
return 0;
}
In case any moderator sees this question, I wanted to talk about negatively asking my question without explanation, and since I explained my doubt, and I left the code right, it’s not the first time it’s happened '-'
– WeslleyAF
I suggest you ask something more specific, and not an entire code waiting for a correction, more details, when we receive an entire code like yours, we often don’t even know the context of this code, so users negatively question your question. Now about the question.
– Luis Eduardo
Note that your program will only work properly if your file has a maximum of 5 records, as you do not test if you have extrapolated the maximum amount set to the array.
– anonimo