title: Hex file reading in C, some data corrupted?
body: <p>Iam having a problem with my school project. When i try to read in C program some hex data from a binary file i get some data filled with F's like this</p>
  
  <pre><code>00 64 61 56 03 00 00 00 09 00 00 00 73 00 00 00 
  6A 69 75 FFFFFFE8 FFFFFFD1 5B FFFFFF8C FFFFFF93 73 FFFFFFAF 19 FFFFFF87 FFFFFFC1 4D FFFFFFFD FFFFFF93 
  FFFFFFDF FFFFFFBE FFFFFFA0 09 FFFFFFBE FFFFFFD4 FFFFFFEB FFFFFFDE FFFFFFD3 FFFFFFF9 FFFFFFBD FFFFFFE6 FFFFFFFA FFFFFFAA 7E 29 
  FFFFFFD3 FFFFFFE2 13 FFFFFFA5 3F FFFFFFA0 3A FFFFFFB2 50 53 3B 12 FFFFFFA1 39 FFFFFFA6 FFFFFF82 
  FFFFFFF7 
  </code></pre>
  
  <p>While the original file in hexdump looks like this:</p>
  
  <pre><code>0000000 6400 5661 0003 0000 0009 0000 0073 0000
  0000010 696a e875 5bd1 938c af73 8719 4dc1 93fd
  0000020 bedf 09a0 d4be deeb f9d3 e6bd aafa 297e
  0000030 e2d3 a513 a03f b23a 5350 123b 39a1 82a6
  0000040 00f7
  </code></pre>
  
  <p>Iam not quiet sure, why is this happening.</p>
  
  <p>I tested it using <a href="https://stackoverflow.com/questions/22057846/hex-file-reading-in-c-programming">this</a> code:</p>
  
  <pre><code>int main()
  {
     char ch, file_name[25];
     FILE *fp;
  
     printf("Enter the name of file you wish to see\n");
     fgets(file_name, sizeof(file_name), stdin);
     file_name[strlen(file_name)-1] = 0x00;
  
     fp = fopen(file_name,"rb"); // read binary mode
  
     if( fp == NULL ) //error checking
     {
        perror("Error while opening the file.\n");
        exit(EXIT_FAILURE);
     }
  
     printf("The contents of %s file are :\n", file_name);
  
     int i;
     while( ( ch = fgetc(fp) ) != EOF )
     {
        printf("%02X ",ch);
        if( !(++i % 16) ) putc('\n', stdout);
     }
     fclose(fp);
     putc('\n', stdout);
  
     return 0;
  }
  </code></pre>