title: fscanf in C segmentation error
body: <p>I am trying to read in values from a file and store them in a structure.</p>
  
  <p>The structure contains</p>
  
  <pre><code>char region
  char country[100]
  int country_code
  </code></pre>
  
  <p>The instance of this structure is called c[100]</p>
  
  <p>The file i am trying to read in looks like this</p>
  
  <pre><code>Europe
  0 France
  1 England
  2 Germany
  </code></pre>
  
  <p>There are an unkonwn number of countries, so it has keep reading until EOF.</p>
  
  <p>I have created an array of the structures.</p>
  
  <p>The code i have so far looks like this:</p>
  
  <pre><code>fp= fopen(countries,"r");
  
      while (!feof(fp))
      {
      fscanf(fp, "%[^\n]", c.region);
          while (!feof(fp))
          {
          fscanf(fp, "%d, %[^\n]", c[i].country_code, c[i].country);
          i++;
          }
      }
  </code></pre>
  
  <p>I get a segmentation fault. I'm sure its something obvious that ive missed out or done wrong, but im not sure what, and i would be grateful if anyone could help.</p>