title: Why would you check that fscanf returns value < 1 in a function?
body: <p>I was given a problem to solve using fscanf which states the following:</p>
  
  <p><em>Write a function to initialize array x of size SIZE with integers read from a text file. The function receives the name of the file as an argument.</em></p>
  
  <p>The solution states the following below. Why would fscanf return a value &lt; 1 if you're scanning each integer in the file? Shouldn't it be > 0 since fscanf returns the number of elements scanned?</p>
  
  <pre><code>void init (char *name)
  {
      FILE    *fp;
      int i;
  
      fp = fopen (name, "r");
      if (fp == NULL)
      {
          printf ("no file\n");
          return;
      }
  
      for (i = 0; i &lt; SIZE; i++)
      {
          if (fscanf (fp, "%d", &amp;x[i]) &lt; 1)
          {
              printf ("got %d numbers\n", i);
              return;
          }
      }
  
      fclose (fp);
      return;
  }
  </code></pre>