title: Debug Assertion Failed Buffer != NULL
body: <p>Hello I got a college project to read Wav file with any Language possible so i chose C/C++ i think i got everything right but 1 thing  i have been working on 
  the c project i always get this msg   "Buffer != NULL"   </p>
  
  <p>the full code : </p>
  
  <pre><code>int main (){
      //char id[10];
      FILE *wav;
      wav=fopen("sound.wav","rb");
  
      if(wav){
          BYTE wav_id[5], *sound_buffer;      
          DWORD size;
  
          short format_tag, channels, block_align, bits_per_sample;
          DWORD format_length, sample_rate, avg_bytes_sec,datasize,i;
  
          fread(&amp;wav_id,sizeof(BYTE),4,wav);
          wav_id[sizeof(BYTE)+3]=0;   
  
          if (!memcmp(&amp;wav_id,"RIFF",4)) {
              fread(&amp;size,sizeof(DWORD),1,wav);
              fread(&amp;wav_id,sizeof(BYTE),4,wav); 
              if (!memcmp(&amp;wav_id,"WAVE",4)) { //this is probably a wave file since it contained "WAVE" 
  
                  fread(&amp;wav_id,sizeof(BYTE),4,wav); //read in 4 bytes "fmt "; 
                  fread(&amp;format_length,sizeof(DWORD),1,wav);
                  fread(&amp;format_tag, sizeof(short), 1, wav); 
                  fread(&amp;channels, sizeof(short),1,wav); 
                  fread(&amp;sample_rate, sizeof(DWORD), 1, wav); 
                  fread(&amp;avg_bytes_sec, sizeof(short), 1, wav); 
                  fread(&amp;block_align, sizeof(short), 1, wav); 
                  fread(&amp;bits_per_sample, sizeof(short), 1, wav); 
                  fread(&amp;wav_id, sizeof(BYTE), 4, wav); //read in 'data' 
                  fread(&amp;datasize, sizeof(DWORD), 1, wav); //how many bytes of sound data we 
                  sound_buffer=(BYTE *)malloc(sizeof(BYTE) * datasize);
                  fread(sound_buffer, sizeof(BYTE), datasize, wav);  // i trace the problem to this line the whole above code seems to run smooth 
              }
              cout &lt;&lt; "\n The file is Riff but it's not a wav file"&lt;&lt;endl;
          }
          else {
              cout &lt;&lt;"\nNOT a Wav File\n"&lt;&lt;endl;}
  
          }
      else {
          cout &lt;&lt;"\nFile wasn't opened\n"&lt;&lt;endl;
      }
  
      system("pause");
  }
  </code></pre>