I m getting 37376 instead of 146 for width and 27393 instead of 363 for height. I guess big endian-small endian problem has occured. plz help me to solve this problem.
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char type[3];
char code[3];
unsigned short int width;
unsigned short int height;
char flags;
char bgColorI;
char pARatio;
}__attribute__((packed)) HEADER;
int main(int argc,char **argv)
{
FILE *fptr;
HEADER header;
if (argc < 2) {
fprintf(stderr,"Usage: %s filename\n",argv[0]);
exit(-1);
}
if ((fptr = fopen(argv[1],"r+b")) == NULL) {
fprintf(stderr,"Unable to open GIF file \"%s\"\n",argv[1]);
exit(-1);
}
fread(&header,sizeof(HEADER),1,fptr);
printf("\n Width = %d , Height =%d\n", header.width,header.height);