Possible Duplicate:
How to read a binary file in c? (video, images, or text)
I am trying to read the contents of a bmp file using a C program. I am able to read the contents but the values read are on contradiction to what I expected. My code is :
FILE *fp=NULL;
fp=fopen("C:\\Users\\Saurabh\\Pictures\\nice.bmp","r");
if(fp!=NULL)
{
printf("%c\n",fgetc(fp));
printf("%c\n",fgetc(fp));
printf("%c\n",fgetc(fp));
printf("%c\n",fgetc(fp));
printf("%c\n",fgetc(fp));
printf("%c\n",fgetc(fp));
}
else
printf("Error reading the file");
I am just reading byte by byte here, just for the sake of understanding. The first two bytes read BM
which is correct. The next four byte reads *t
. The value expected is 40. Please see the format. Can someone please explain waht is happening and how can I get the value 40
if I need to perform some conversions.