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:

  1. use fopen open file , create file pointer.
  2. use fread read contents of file buffer.
  3. use strtol convert numbers in buffer long int; note there other functions other other type conversions.
  4. use fclose close file , free file pointer

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -