title: Read line in C++ till EOF
body: <p>I'm writing a function that reads line by line from <code>cin</code> and returns when it sees <code>;</code> character. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string.h&gt;
  
  using namespace std;
  
  int read_cmd(char *cmd)
  {
      cout &lt;&lt; "Please enter a string: \n";
      cmd[0]='\0';
  
      while(1){
          char currentLine[10000];
          currentLine[0]='\0';
          cin.getline(currentLine,10000);
          if (strcmp(currentLine,";")==0){
              break;
          }
          strcat(cmd, "\n");
          strcat(cmd, currentLine);
      }
      return 0;
  }
  
  int main(){
      char cmd[1000];
      while (1){
          read_cmd(cmd);
          cout&lt;&lt; cmd &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>I then tested it using text fed from another file via pipe. 
  ./read_cmd &lt; test_file</p>
  
  <p>contents of test_file:</p>
  
  <pre><code>line 1
  line 2
  ;
  </code></pre>
  
  <p>This outputs results just fine, however it gives me a segmentation fault at the end. Is there a way for <code>cin</code> to check if it's coming across an EOF and terminates? </p>