title: c++, reading files, segmentation fault
body: <p>I was working on this function read. The <code>main</code> I used has no problem in file I/O, it connects fine, closes, the files are okay too. However, I am getting a segmentation fault by the end of the reading. I have tried printing out for testing, and the error is reading the last line. It finishes reading the last line for string <code>a</code>, and then <code>x</code>, and then <code>in.good()</code> becomes false too. I have tried resetting <code>in.clear()</code>, also, setting the string <code>a="";</code> if <code>in.good</code> becomes false. Nothing is working.</p>
  
  <pre><code>read(istream&amp; in){
      string a;
      int x;
      in&gt;&gt;a;
      while( in.good() ){
          in&gt;&gt;x;
          char *ch;
          strcpy( ch, a.c_str() );
          Word cwd(ch);
          anObject.add(cwd,x);   
      }
  }
  </code></pre>