Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C structs & fread

Name: Anonymous 2007-11-23 2:52

I have a struct i want to read in from file. To be specific its a windows bmp. It works when i read in the values individually, but when I try and read the structure as a whole it gets the wrong values:


struct BITMAPFILEHEADER{
    unsigned short bfType;        // size: 2
    unsigned int bfSize;        // size: 4
    unsigned short bfReserved1;    // size: 2 
    unsigned short bfReserved2;    // size: 2 
    unsigned int bfOffBits;    //size: 4
};

// works
fread (&fileheader.bfType,2,1,imgFile);
fread (&fileheader.bfSize,4,1,imgFile);
fread (&fileheader.bfReserved1,2,1,imgFile);
fread (&fileheader.bfReserved2,2,1,imgFile);
fread (&fileheader.bfOffBits,4,1,imgFile);

// does not work right
fread (&fileheader,sizeof(BITMAPFILEHEADER),1,imgFile);

Name: Anonymous 2007-11-23 3:12


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List