BMP decoding

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jojyjoseph
    New Member
    • Oct 2011
    • 2

    BMP decoding

    I was trying to decode bmp file.
    #include<stdio. h>

    int main ()
    {
    FILE *fp;
    char a[2];
    fp=fopen("black buck.bmp","r");
    fread(a,sizeof( short int),1,fp);
    fclose(fp);
    a[2]='\0';
    printf("value %x\n",a);
    return 0;
    }

    but the value it shows is coming different. The value is 4d42 for BM. but it is computing 22cd32.

    THanks in advance
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    because its printing the base address of the the array,

    your printf statement would be
    Code:
    printf("value %x\n",a[0])
    if you read binary number then read as unsigned char

    Comment

    • jojyjoseph
      New Member
      • Oct 2011
      • 2

      #3
      THanks,

      for the correction

      Comment

      Working...