I'm trying to read the header of a bmp image and get the width and height of it into my struct, but as you can see in my code, i was trying to fread file header into my char array header
, it shows BM6 in terminal and i really have no idea what is it. And how to pass them into my struct.
#include <stdio.h>
struct __attribute__((__packed__)) BitmapHeader
{
int width;
int height;
};
void loadBmp(char* filePath, struct BitmapHeader *bmpHeaderInfo){ //pass struct by ref
FILE* filePointer = fopen(filePath, "rb");
if (filePointer == NULL)
return NULL;//temp!
unsigned char header[54];
fread(header, sizeof(unsigned char), 54, filePtr);
//fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
printf("%s\n", header);
}
int main(){
char path2BMP[] = "cup.bmp";
struct BitmapHeader bmpHeaderInfo = {0};
loadBmp(path2BMP, &bmpHeaderInfo);
return 0;
}