title: FILE I/O in C++ throws an error
body: <pre><code>int main(array&lt;System::String ^&gt; ^args)
  {
  
  FILE* fp;
  char str[1];
  int x = 0;
  
  fp = fopen("C:\\input.txt", "r");
  
  do{
      x = fscanf(fp, "%s", str);
  
      if (x != -1)  // So that the last string is not printed twice
      {
          printf("%s ", str);
      }
  
    }while (x != -1);
  
  return 0;
  
  }
  </code></pre>
  
  <p>This program prints the correct output. BUT after printing, it throws an error in windows saying "Program stopped working". Also IF there is no text in the notepad file i.e if it is blank, then it shows no error. Please explain!</p>