title: Read the next line of a file every time a function is called
body: <p>I have a text file with numbers on each line. I want to write a function in C that reads in the file and returns the next number in the file every time the function is called.</p>
  
  <p>For example if I have these numbers: </p>
  
  <pre><code>100 
  200 
  300 
  400
  </code></pre>
  
  <p>and a function called get_number(), if I call get_number() it will return 100, if I call it again, it will return 200, etc.</p>
  
  <p>This is what I've written so far but every time the function is called, it always goes back to the first number in the text file.</p>
  
  <pre><code>int * get_number()
  {
  
      FILE* file = fopen("random_numbers.txt", "r");
      char line[256];
  
      if (file==NULL) 
      {
          perror ("Error reading file");
      }
      else
      {
          fgets(line, sizeof(line), file);
          printf("%s", line);
      }
  
      return 0;
  }
  </code></pre>