title: Import data from txt file into C program
body: <p>I need to import some data from a <code>data.txt</code> file in a C program. My data source is like this:</p>
  
  <pre><code>A ABC001 B
  A ABC002 B
  A ABC003 C
  B ABC004 C
  B ABC005 E
  C ABC006 B
  D ABC007 A
  D ABC008 B
  E ABC009 D
  </code></pre>
  
  <p>I have defined a new data type to hold all the information:</p>
  
  <pre><code>typedef struct node {
      char street_name;
      char number_plate[7];
      char destination;
  } Car;
  </code></pre>
  
  <p>Here it is my attempt to import the data from the file above into an array:</p>
  
  <pre><code>int main(void)
  {
      FILE *file;
      int i = 0;
      Car carinfo[9];
  
      file = fopen("data.txt", "r");
  
      while (EOF != fscanf(file, "%c %6s %c", &amp;carinfo[i].street_name,
                                              &amp;carinfo[i].number_plate, 
                                              &amp;carinfo[i].destination))
      {
          printf("Loop #%d\n", i+1);
          i++;
      }
  
  
  
      for (i = 0; i &lt; 9; i++)
      {
          printf("Street Name: %c, Number Plate: %s, Destination: %c\n", carinfo[i].street_name, 
                                                                         carinfo[i].number_plate, 
                                                                         carinfo[i].destination);
      }
  
      fclose(file);
      return 0;
  }
  </code></pre>
  
  <p>The <code>while</code> loop is being executed for 10 times and then makes the program crash, because apparently it disregards the <code>EOS</code> that should prevent another iteration. </p>
  
  <p>What is that I am doing wrong here? Can anyone please help me figure out?</p>