title: Bus error (core dumped) with Linked Lists?
body: <p>I'm writing a program that allows a user to type in a file name of a person database to be read; the program then creates a linked list of state objects and a linked list of person objects within each state link to organize the information from the file. </p>
  
  <p>I know the linked list part works because I was able to directly code in the file name and print out the list of states and the list of people in each state; however, when I try to allow the user to type in the file name as a command, I'm getting a Bus error. When I run the code in gdb, all it tells me is:</p>
  
  <pre><code>Program received signal SIGBUS, Bus error.
  0x280df0bd in std::operator&gt;&gt;&lt;char, std::char_traits&lt;char&gt; &gt; ()
     from /usr/lib/libstdc++.so.5
  </code></pre>
  
  <p>I don't even get a line number to go off of! Any help would be super appreciated. Here's the command and read portions of my code: </p>
  
  <pre><code>List&lt;State*&gt;* read(char* filename) {
      string fname, lname, birthday, state;
      int ssn;
      List&lt;State*&gt;* state_list = new List&lt;State*&gt;();
  
      ifstream file(filename);
      if (file.fail()) {
          cerr &lt;&lt; "Error reading file.\n";
          exit(1);
      }
  
      while (!file.eof()) {
          file &gt;&gt; birthday &gt;&gt; ssn &gt;&gt; fname &gt;&gt; lname &gt;&gt; state;
          Link&lt;State*&gt;* searchres = searchList(state, state_list);
          Person* p = new Person(fname, lname, ssn, birthday, state);
          if (searchres == NULL) // create new state
          {
              State* addedstate = state_list-&gt;addLink(new State(state))-&gt;data;
              addedstate-&gt;res_list.addLink(p);
          }
  
          else // add to pre-existing state
          {
              searchres-&gt;data-&gt;res_list.addLink(p);
          }
      }
      return state_list;
  }
  
  void main() {
      string cmd;
      cout &lt;&lt; "Type your command in all lowercase letters.\n";
      cin &gt;&gt; cmd;
      if (cmd == "read") {
          char* filnm;
          cin &gt;&gt; filnm;
          List&lt;State*&gt;* state_ls = read(filnm);
          Link&lt;Person*&gt;* counter = state_ls-&gt;first-&gt;data-&gt;res_list.first;
          while (counter != NULL) {
              cout &lt;&lt; counter-&gt;data-&gt;ssn &lt;&lt; "\n";
              counter = counter-&gt;next;
          }
      }
  }
  </code></pre>