title: fgets() reads and stores a char form a line twice
body: <p>So I have a file <code>data.txt</code>, with random integers written in it, for example <code>&quot;17 12 5 4 16&quot;</code>.</p>
  <p>So, I used <code>fgets()</code> to read this line of integers and store it in a <code>char str []</code>. As expected <code>str [0] == 17</code>, but <code>str [1] == 7</code>, an so on... every 2 digits the integer is stored in an element in the array, but the second digit is also stored in the following element.</p>
  <p><strong>Example:</strong> <code>str [3] = 12</code>, <code>str [4] = 2</code>, <code>str[5] = ' '</code>.</p>
  <p>What could be done to fix this issue?</p>
  <p>Here is my very typical code:</p>
  <pre><code>    FILE* fp = fopen (&quot;data.txt&quot;, &quot;r&quot;);
  
      int i = 0, j = 0;
      int size = fileSize(fp) + 1; // Enumerate the char numbers in file
      char str [size];
      rewind (fp);
      fgets (str, size, fp);
  
  </code></pre>
  <p>Here is my entire code</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;ctype.h&gt;
  
  typedef struct RATIONAL
  {
      int top;
      int bottom;
  } RATIONAL;
  
  void printArray (int arr [], int count)
  {
      for (int i = 0; i &lt; count; ++i)
      {
          printf (&quot;%d\n&quot;, arr[i]);
      }
  }
  
  int fileSize (FILE* fp)
  {
      char c;
      int i = 0;
      while ((c = getc (fp)) != EOF)
      {
          i++;
      }
      return (i);
  }
  
  int main ()
  {
      RATIONAL ratArray [23];  //array to hold rational numbers
      int intArray [45]; //array to hold integer values
  
      FILE* fp = fopen (&quot;data.txt&quot;, &quot;r&quot;);
  
      int i = 0, j = 0;
      int size = fileSize(fp) + 1; // Enumerate the char numbers in file
      char str [size];
      rewind (fp);
      fgets (str, size, fp);
  
      //Convert string to array of ints
      while (i &lt; size -1)
      {
          if (isdigit (str [i]))
          {
                  intArray[j++] = atoi(&amp;str[i]);
                  i++;
          }
          else
              i++;
      }
          printArray (intArray, intArray[0]);
  </code></pre>
  <p>Input: <a href="https://1drv.ms/t/s!Avugtf3caxPuiRPfZWTBPvsYODPg?e=IcUo23" rel="nofollow noreferrer">data.txt</a></p>