title: searching an integer from a text file in c
body: <p>I have a simulation program written in c and I need to create random numbers and write them to a txt file. Program only stops 
  - when a random number already generated is generated again or
  - 1 billion random number are generated (no repetition)</p>
  
  <p>My problem is that I could not search the generated long int random number in the txt file!
  Text file format is:
  9875
  764
  19827
  2332
  ...
  Any help is appreciated..
  `</p>
  
  <pre><code>FILE * out;
  
  int checkNumber(long int num){
      char line[512];
      long int number;  
      int result=0; 
  
      if((out = fopen("out.txt","r"))==NULL){
              result= 1;
      }
  
      char buf[10];
      itoa(num, buf, 10);
  
  
      while(fgets(line, 512, out) != NULL)
      {
         if((strstr(line,buf)) != NULL){
                result = 0;
         }
      }
      if(out) {
          fclose(out);
      } 
      return result;  
  }
  
  
  int main(){
      int seed;
      long int nRNs=0;
      long int numberGenerated;     
      out = fopen ("out.txt","w");
  
      nRNs=0;
      seed = 12345;
  
      srand (seed);  
  
      fprintf(out,"%d\n",numberGenerated);
      while( nRNs != 1000000000 )
      {
        numberGenerated = rand();
        nRNs++;
  
        if(checkNumber(numberGenerated)==0){
            fclose(out); break; system("pause"); 
        }
        else{
            fprintf(out,"%d\n",numberGenerated);
        }
  
      }    
  
      fclose(out);
  </code></pre>
  
  <p>}`</p>