title: Reading in C using fscanf multiple values
body: <p>From a text file of the following format:</p>
  
  <pre><code>Name Surname ID Address
  Name Surname ID Address
  Name Surname ID Address
  </code></pre>
  
  <p>I need to extract each one and put it in a variable.</p>
  
  <p>I tried the following two methods:</p>
  
  <pre><code>while(fscanf(fp, "%s,%s,%d,%s\n", name2,surname2,&amp;id2,address2) != EOF){
      printf("Name: %s, Surname: %s, ID: %d, Address: %s\n",
          &amp;name2, &amp;surname2, &amp;id2, &amp;address2);
  }
  </code></pre>
  
  <p>Which gives me the wrong results it only reads one word for each line so the result is something like this:</p>
  
  <pre>
  Name: Name Surname:@,a ID:2272012 Address: ?"
  Name: Surname Surname:@,a ID:2272012 Address: ?"
  Name: ID Surname:@,a ID:2272012 Address: ?"
  Name: Address Surname:@,a ID:2272012 Address: ?"
  </pre>
  
  <p>And the other method I used was:</p>
  
  <pre><code>while(fscanf(fp, "%s,%s,%d,%s\n", name2,surname2,&amp;id2,address2) == 4){
      printf("Name: %s, Surname: %s, ID: %d, Address: %s\n",
          &amp;name2, &amp;surname2, &amp;id2, &amp;address2);
  }
  </code></pre>
  
  <p>Which reads nothing and nothing happens.</p>
  
  <p>The file I'm reading from is .dat and it's for an assignment and so can only use .dat.</p>