title: Why using fread() the 2-nd time it reads a file not from beginning but from the end of reading by the 1-st fread()?
body: <p>I'm want to fill <code>hdr</code> (struct) variable with data from <code>in.wav</code> file and I want to copy the first 64 bytes of <code>in.wav</code> file to another file (<code>out.wav</code>).</p>
  
  <p>But! When using <code>fread()</code> the second time it starst to copy <code>in.wav</code> from the place where it finished when using <code>fread()</code> the first time. Why?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  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]; // 10 secs of garbage. he-he)
  } 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");
      FILE *output = fopen("out.wav", "wb");
  
      unsigned char buf[64];
      header hdr;
  
      if(input == NULL)
      {
          printf("Unable to open wave file\n");
          exit(EXIT_FAILURE);
      }
  
      fread(&amp;hdr, sizeof(char), 64, input);
  
  
      fread(&amp;buf, sizeof(char), 64, input);
      fwrite(&amp;buf, sizeof(char), 64, output);
  
  
      printf("\n&gt;&gt;&gt; %4.4s", hdr.ChunkID);
  
      fclose(input);
      fclose(output);
  
      return 0;
  }
  </code></pre>
  
  <p>What is the matter?</p>