Probem reading file, only first record is read
Hello
I'm having problems getting the name of the record saved in txt file.
So i ask the user to choose an id and the name must be retrivied but it only works with fisrt line
This my code
Code:
int loginprofsaude(struct ficha *admissao, int registo) {
char nint2[100];
int a;
printf("\nId: ");
scanf("%s", nint2);
fflush(stdin);
FILE *fadmissao;
fadmissao = fopen("fadmissao.txt", "r+");
while (fscanf(fadmissao, "%s %s %d %s %d %s %d %d %s\n", admissao[registo].nint, admissao[registo].nomecompleto, admissao[registo].idade, admissao[registo].especialidade,admissao[registo].anos, admissao[registo].localidade, admissao[registo].telefone, admissao[registo].salario, admissao[registo].horario)!= EOF) {
a = strcmp(admissao[registo].nint, nint2);
printf("valores %d %d %d", nint2,admissao[registo].nint, a );
if (a == 0) {
printf("\nLogin ok.");
printf("\nName: %s.", admissao[registo].nomecompleto);
fclose(fadmissao);
return 1;
}
}
if (feof(fadmissao)) {
printf(Doesn't exist.");
}
fclose(fadmissao);
return 0;
}
my txt file has this
1 John
2 Maria
So if i put 1...i get John
If i put 2 the program exit
any help?
Thanks