title: Setting a buffer/pointer to null
body: <p>I am trying to constantly read data into a buffer of type unsigned char* from different files. However, I can't seem to set the buffer to NULL prior to reading in the next file.</p>
  
  <p>Here is only the relevant code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;fstream&gt;
  
  
  int
   main (int argc, char** argv) { 
  
       FILE* dataFile = fopen("C:\\File1.txt", "rb");
       unsigned char *buffer = NULL;
       buffer = (unsigned char*)malloc(1000); 
       fread(buffer,1,1000,dataFile);
       fclose(dataFile);
  
       dataFile = fopen("C:\\File2.txt", "rb");
       buffer = NULL;
       fread(buffer,1,1000,dataFile);
       fclose(dataFile);
  
       system("pause");
       return 0; 
  
  }
  </code></pre>
  
  <p>The error I run into is at the second occurrence of this line: <strong>fread(buffer,1,1000,dataFile);</strong></p>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>Debug Assertion Failed! 
    Expression: (buffer != NULL)</p>
  </blockquote>
  
  <p>It points me to Line 147 of fread.c which is basically:</p>
  
  <blockquote>
  <pre><code>/* validation */
  _VALIDATE_RETURN((buffer != NULL), EINVAL, 0);
  if (stream == NULL || num &gt; (SIZE_MAX / elementSize))
  {
      if (bufferSize != SIZE_MAX)
      {
          memset(buffer, _BUFFER_FILL_PATTERN, bufferSize);
      }
  
      _VALIDATE_RETURN((stream != NULL), EINVAL, 0);
      _VALIDATE_RETURN(num &lt;= (SIZE_MAX / elementSize), EINVAL, 0);
  }
  </code></pre>
  </blockquote>
  
  <p>I did Google for ways to get the buffer pointer to NULL and tried the various suggestions, but none seem to work. Anyone can clarify what is the right way to set it to NULL?</p>