title: Visual Studio 2015 shows Debug Assertion Failed
body: <p>I have made a simple file reading program that runs successfully in DEV C gcc compiler, but it shows an error <code>Debug Assertion Failed</code>.
  I searched and someone has asked the same question 12 days ago,
  answer shows that his error was on the statement </p>
  
  <pre><code>if (file = fopen (name, "w+") == NULL) {
    ...
  }    
  </code></pre>
  
  <p>and says the separate the two statements as</p>
  
  <pre><code>file = fopen(name, "w+");
  
  if (fp == NULL) { ...}    
  </code></pre>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;stdlib.h&gt;
  int main()
  {
  
      int nos = 0, noc = 0, nol = 0;
      char ch;
      FILE *fp;
      fp = fopen("Sarju.txt", "r");
      while (1)
      {
          ch = fgetc(fp);
          if (ch == NULL)
          {
              printf("The file didn't opened\n");
              break;
          }
          if (ch == EOF)
              break;
          noc++;
          if (ch == ' ')
              nos++;
          if (ch == '\n')
              nol++;
      }
      if (ch != NULL)
          fclose(fp);
      printf("Number of Space : %d\nNumber of Characters : %d\nNumber of lines : %d\n", nos, noc, nol);
      _getch();
      return 0;
  }    `
  </code></pre>
  
  <p><strong>My Error</strong></p>
  
  <blockquote>
    <p>Debug Assertion failed! Program: ...o 2015\Projects\Let Us C Solutions\Debug\Let Us C Solutions.exe File: minkernel\crts\src\appcrt\stdio\fgetc.cpp Line: 43 Expression: stream.valid() For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application)</p>
  </blockquote>