title: App crashes though I can't understand the reason
body: <p>The input file is <code>in.wav</code>. I have to read chunks (succeeded) and to read samples to normalize the audio file... </p>
  
  <p>The problem is that it crashes while trying to fing the <code>max</code> and <code>min</code> values of .wav file's samples.
  It will just find the minimum value and the maximum one in the array, but it crashes...
  Tell me what is wrong, please.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "main.h"
  #define hdr_SIZE 64
  
  typedef struct FMT
  {
      char        SubChunk1ID[4];
      int         SubChunk1Size;
      short int   AudioFormat;
      short int   NumChannels;
      int         SampleRate;
      int         ByteRate;
      short int   BlockAlign;
      short int   BitsPerSample;
  
  } fmt;
  
  typedef struct DATA
  {
      char        Subchunk2ID[4];
      int         Subchunk2Size;
      int         Data[441000]; 
  } data;
  
  typedef struct HEADER
  {
      char        ChunkID[4];
      int         ChunkSize;
      char        Format[4];
      fmt         S1;
      data        S2;
  } header;
  
  
  
  int main()
  {
      FILE *input = fopen( "in.wav", "rb");   /// nameIn
  
      if(input == NULL)
      {
          printf("Unable to open wave file (input)\n");
          exit(EXIT_FAILURE);
      }
  
      FILE *output = fopen( "out.wav", "wb"); /// nameOut
      header hdr;
  
  
      fread(&amp;hdr, sizeof(char), hdr_SIZE, input); 
      /* NOTE: Chunks has been copied successfully. */
  
  
      /*###############################*/                                  
      /*##### UPDATE (char *ptr;) #####*/
      /*###############################*/
      char *ptr;  // 'int' was written here instead of 'char'. That's was a stupid mistake...
      long n = hdr.S2.Subchunk2Size;
  
  
      /// COPYING SAMPLES...
      ptr = malloc(sizeof(hdr.S2.Subchunk2Size));
      while ( n-- != 0 )
      {
          fread(&amp;ptr, 1, 1, input);  // Continues reading after the least 'stop' place. 
      }                              // I was being told here (on "stack") that it is so...
  
  
      n = hdr.S2.Subchunk2Size; // Resetting 'n'.
      int min = ptr[0], max = ptr[0], i;
  
      /* THE PROBLEM IS HERE: */
      for ( i = 0; i &lt; n; i++ )
          {
              if ( ptr[i] &lt; min )     // If the next elements is less than previous, swap them.
                  min = ptr[i];
              if ( ptr[i] &gt; max ) // If the next elements is bigger than previous, swap them.
                  max = ptr[i];
      }
  
      printf("&gt; &gt; &gt;%d__%d\n", min, max);    // Displaying of 'min' and 'max'.
  
      fclose(input);
      fclose(output);
  
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>EUREKA! This is all because of 8-bits per sample! I must manipulate with them ( with samples ) as with a type of char. (see my "### UPDATE ###"-comment in the code)</p>