title: Segmentation Fault (Core dumped) - where is the error?
body: <p>I have a basic C program that I have to do for a Personal Software Processes assignment. I'm fairly new to C so I honestly can't see where I've gone wrong. Please read through and let me know what I'm doing that's causing it to crash?</p>
  
  <p>I've got to read in a file, and store the values as an array. It comes up with no compiling errors, just a segmentation fault.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define array_limit   100
  
  int main (void)
  
  {  
    FILE *ifp;
    char *mode = "r";
    ifp = fopen("samplepopulation.txt", mode);  
  
  
    if (ifp==NULL)
    {
      printf("cannot read file \n");
    }  
    else
    {   
      int i;
      float sample; 
  
      float values[array_limit];
      i = 0;
  
      do
      {
         fscanf(ifp, "%f", &amp;sample);
         if (!feof(ifp))
         {
            values[i] = sample;
            printf("%f \n", values[i]);
            i++;
              if (i&gt;array_limit)
              {
                 printf("File larger than allowed/n");
                 break;
              }
         }
  
         else
         {
            printf("read complete");
         }
  
      } while (ifp!= EOF);     
    }
  
    fclose(ifp);
  
    return 0;
  }
  </code></pre>