title: How do I read character by character from a text file and put it in a character array?
body: <p>I'm trying to read character by character from a text file until EOF, put them into a character array, so that I can manipulate it after. Compiled with g++ without errors, and when run, I'm prompted for the input file but then it just hangs.  </p>
  
  <pre><code>int main (int argc, char *argv[]) {
      string filename;
      ifstream infile;
  
      char *cp, c[1024];
      memset (c, 0, sizeof(c));
      cp = c;
  
      cout &lt;&lt; "Enter file name: " &lt;&lt; endl;
      cin &gt;&gt; filename;
  
      //open file
      infile.open( filename.c_str() );
  
      //if file can't open
      if(!infile) {
          cerr &lt;&lt; "Error: file could not be opened" &lt;&lt; endl;
          exit(1);
      }
  
      while (!infile.eof()); {
          infile.get(c, sizeof(infile));
         // get character from file and store in array c[]
      }
  }//end main
  </code></pre>