title: C read space-separated values from file
body: <p>I need to read text from a file and assign values to a struct based on information read.</p>
  
  <p>Here is the format of the text file:  </p>
  
  <pre><code>First Middle Last   Address          city     state zip age sex tenure salary  
  \--------------------------------------------------------------  
  ADA     A AGUSTA    33 BABBAGE ROAD  LOVELACE    GB 19569 28 F 2 350.50  
  ISSAC   A ASIMOV    99 FICTION WAY   AMHERST     MA 63948 58 M 6 423.88  
  HUMPHRY R BOGART    71 SAM STREET    HOLLYWOOD   CA 48482 56 M 5 366.00  
  </code></pre>
  
  <p>And the struct I have to read it into:  </p>
  
  <pre><code>typedef struct  
  {  
  char first[8], initial, last[10],  
  street[17], city[12], state[3];  
  int age, tenure, zip;  
  float salary;  
  char sex;  
  }Employee;  
  </code></pre>
  
  <p>The code I have used so far has been:  </p>
  
  <pre><code>void inputLine(Employee* e)  
  {  
  fscanf(pay, "%s %s %s %s %s %s %s %s %d %d %s %d %f",  
             e-&gt;first, &amp;e-&gt;initial, e-&gt;last, e-&gt;street,  
             e-&gt;street, e-&gt;city, e-&gt;city, e-&gt;state,  
             &amp;e-&gt;zip, &amp;e-&gt;age, &amp;e-&gt;sex, &amp;e-&gt;tenure,  
             &amp;e-&gt;salary);  
  }  
  </code></pre>
  
  <p>But when I print each line, the first few lines are fine, then things start messing up:  </p>
  
  <pre><code>TED L KOPPEL ABC WASHINGTON DC 37376 48 M 9 909.44  
  DAVID T LETTERMAN WNBC NEW YORK 0 0   
  NY 1 47 5 STEVIE R 0 0   
  NICKS 3 MUSIC CHICAGO 23459 38 0 0   
  F 8 460.88 P 76 SILLY 0 89   
  STREET L GB 44 2 320.50 0 12341   
  </code></pre>
  
  <p>I have also tried:  </p>
  
  <pre><code>void inputLine(Employee* e)  
  {  
  char line[53];  
  fgets(line, 52, pay);  
  printf("%s\n", line);  
  fflush(stdout);  
  sscanf(line, "%s %s %s %s %s %s %s %s %d %d %s %d %f",  
  e-&gt;first, &amp;e-&gt;initial, e-&gt;last, e-&gt;street,  
  e-&gt;street, e-&gt;city, e-&gt;city, e-&gt;state,  
  &amp;e-&gt;zip, &amp;e-&gt;age, &amp;e-&gt;sex, &amp;e-&gt;tenure,  
  &amp;e-&gt;salary);  
  }  
  </code></pre>
  
  <p>But that gives the same result.</p>
  
  <p>The code cannot be in C++.
  I am using the Linux GNU GCC 4.8.1 compiler, but I have also tested this on Mac's compiler and it did not work.</p>