title: Read the first integer in a binary file
body: <p>Having a binary file that holds:</p>
  
  <pre><code># hexdump file.pak 
  0000000 09 00 00 00 
  0000004
  </code></pre>
  
  <p>trying to read it with fread results in :</p>
  
  <pre><code>int main(void){
    char *filename = "file";
    FILE *fh = header_open(filename);
    header_init(fh);
    header_read_num_files(fh);
    header_close(fh);
  }
  
  FILE *header_open(char *pkg_file){
    FILE *fh;
    // open file with binary/read mode                                                                                                                                               
    if ( (fh = fopen(pkg_file, "ab")) == NULL){
      perror("fopen");
      return NULL; // todo: ...                                                                                                                                                      
    }
  
    return fh;
  }
  
  int header_read_num_files(FILE *fh){
    fseek(fh, 0L, SEEK_SET);
    char c;
    fread(&amp;c, sizeof(char), 1, fh);
    fprintf(stderr,"buff received: %d\n", c);
  }
  
  /* write first 0 for number of files */
  void header_init(FILE *fh){
    unsigned int x= 9;
    fseek(fh, 0, SEEK_SET);
    fwrite( (const void*)&amp;x, sizeof(int), 1, fh);
  }
  
  
  output: buff received: 112
  </code></pre>
  
  <p>My system uses the small-endianness conversion. but still the other bytes are set to zero, I cannot really see why I'm getting this output. </p>
  
  <p>An explanation is much appreciated. </p>