title: Segmentation Fault 11 in C++ processing text file
body: <p>I am trying to write a program in C++ in Mac to process a text file (table.txt) that has the following data: </p>
  
  <blockquote>
    <p>Tom 50 60 70.5<br>
    Jerry 80.3 65 91<br>
    Mark 75.2 77 92.7<br>
    Lucy 100 87.6 93  </p>
  </blockquote>
  
  <p>However, what I get from running it on terminal is this, with segmentation fault 11: </p>
  
  <blockquote>
    <p>Tom 50 60 70.5<br>
    Jerry 80.3 65 91<br>
    Mark 75.2 77 92.7<br>
    Segmentation fault: 11   </p>
  </blockquote>
  
  <p>Here is my program: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct StudentList {
      string name;
      double scores[2];
  };
  
  int main() {
  
      ifstream marks;
      marks.open("table.txt");
  
      StudentList Student[50];
  
      int index = 0;
  
      string text;
      if (marks.fail()) {
          cout &lt;&lt; "fail open" &lt;&lt; endl;
      }
  
      while (marks &gt;&gt; text) {
          cout &lt;&lt; text &lt;&lt; " ";
          Student[index].name = text;
          marks &gt;&gt; Student[index].scores[0];
          cout &lt;&lt; Student[index].scores[0] &lt;&lt; " ";
  
          marks &gt;&gt; Student[index].scores[1];
          cout &lt;&lt; Student[index].scores[1] &lt;&lt; " ";
  
          marks &gt;&gt; Student[index].scores[2];
          cout &lt;&lt; Student[index].scores[2] &lt;&lt; " ";
  
          cout &lt;&lt; endl;
          index++;
          cout &lt;&lt; index &lt;&lt; endl;
      }
  
      marks.close();
  
      return 0;
  }
  </code></pre>
  
  <p>What exactly is the problem? </p>