c - How compare number with numbers inside myfile -
i'm developing software , need insert students , check if same students registered in system.
int setnumaluno() //definir num de aluno { int num; printf("\n"); printf("numero de aluno: \n"); scanf("%d", &num); printf("a verificar se existe o aluno\n"); checkstudent(num); return num; } void checkstudent(int num)//metodo responsavel por verrificar no ficheiro se o mesmo existe { int numerofile=0; int r = 0; while (numerofile != eof) { numerofile = fscanf(fp, "%d", &r); if (num == numerofile) printf("numero existe"); else if (num != numerofile) setnomealuno(); } }
i've tryed implement while cycle can't check if number exists in file. file called when fscanf()
instruction can't check if have member number. how can perform, code, verify if student exists or not?
do way:
- use
fopen
open file , createfile
pointer. - use
fread
read contents of file buffer. - use
strtol
convert numbers in bufferlong int
; note there other functions other other type conversions. - use
fclose
close file , freefile
pointer
Comments
Post a Comment