0
I’m having trouble reading data from a file and writing it into a vector and matrix. I can’t give the printf
to test them. So I’m not sure if the code is correct. The file has student names and their enrollments respectively.
#include stdio.h
#include stdlib.h
#include string.h
#define TOT 5
int le_alunos(char nome_al[], int matricula_al[][TOT+1]){
int i=0, c;
FILE *alunos;
alunos = fopen("ALUNOS.TXT","r");
if(alunos == NULL){
printf("Erro ao abrir o arquivo \"ALUNOS.TXT\" ");
exit(1);
}
c = fscanf(alunos,"%[^\n] %d", &nome_al[i], matricula_al[i]);
while(c==2){
i++;
printf("Nome:%s...................Matricula:%d", nome_al[i],matricula_al[i]);
}
fclose(alunos);
return i;
}
int main(void){
int i;
char nome_al[81];
int matricula_al[2][TOT+1];
int papagaio;
papagaio = le_alunos(nome_al,matricula_al,i);
return 0;
}
I could not identify in your explanation what the problem you are having. Give more details of what is happening.
– Maniero
You should [Dit] your question to put new information and not answer it, unless you have already solved the problem and want to post the solution found to help other people.
– Maniero
Well I have a file . txt that has students' names and their enrollments. I want to read this file and store the names in an array, and the plates in an array. Only that I put that printf inside the while so that he was informing me what he’s already saving. Only when running the program it does not appear anything on the console... So I do not know if the program is entering into while or not. I did some tests and I couldn’t come to any conclusion...
– Guilherme