I'm having trouble reading data from a file and writing it to a vector and array. I can not give 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;
}