title: c++ issue reading file into struct
body: <p>When running in terminal I get  segmentation fault when the following code is executed. In Xcode it didn't work either, but it let the program continue anyway and I just assumed it was a file path issue. Any ideas of what I'm doing wrong? The issue comes when <code>createPuzzleList</code> is called.</p>
  
  <pre><code>enum attribute_t {MONEY, TIME, INTEL};
  enum action_t {PENALTY, REWARD};
  const ushort MAX_NUM_ACTIONS = 3;
  
  struct action {
      action_t actType;
      attribute_t attType;
      ushort points;
  };
  struct puzzle {
      string question;
      string key;
      ushort numActions;
      action actionArray[MAX_NUM_ACTIONS];
      puzzle* nextPuzzle;
  };
  
  typedef puzzle* puzzlePtr;
  
  struct puzzleDB {
      ushort numberOfPuzzles;
      puzzlePtr puzz;
  };
  
  int createPuzzleList(puzzleDB&amp; puzzles, string filename) {
      ifstream inStream;
      inStream.open((char*)filename.c_str());
      if (inStream.fail()) {
          cout &lt;&lt; "Input file opening failed." &lt;&lt; endl;
          return 1;
      }
      string actType;
      string attType;
      ushort points;
      puzzlePtr cur;
      while (!inStream.eof()) {
          inStream &gt;&gt; puzzles.puzz-&gt;question;
          inStream &gt;&gt; puzzles.puzz-&gt;key;
          inStream &gt;&gt; puzzles.puzz-&gt;numActions;
          for (int i = 0; i &lt; puzzles.puzz-&gt;numActions; i++) {
              action act;
              inStream &gt;&gt; actType;
              if (actType == "PENALTY") { act.actType = PENALTY;}
              else {act.actType = REWARD;}
              inStream &gt;&gt; attType;
              if (attType == "MONEY") {act.attType = MONEY;}
              else if (attType == "TIME") {act.attType = TIME;}
              else {act.attType = INTEL;}
              inStream &gt;&gt; points;
              act.points = points;
              puzzles.puzz-&gt;actionArray[i] = act;
          }
          puzzles.puzz = puzzles.puzz-&gt;nextPuzzle;
          puzzles.numberOfPuzzles++;
      }
      inStream.close( );
      return 0;
  }
  </code></pre>