我有以下代码从文件读取到结构和数组中。当我尝试在结构中打印数据时,这不是我所期望的。该数组打印出预期的内容,即文件中的前两个字符。
typedef struct __attribute__((packed)){
uint8_t magic[2]; /* the magic number used to identify the BMP file:
0x42 0x4D (Hex code points for B and M).
The following entries are possible:
BM - Windows 3.1x, 95, NT, ... etc
BA - OS/2 Bitmap Array
CI - OS/2 Color Icon
CP - OS/2 Color Pointer
IC - OS/2 Icon
PT - OS/2 Pointer. */
} bmp_header_t;
bool
bmp_get_header_from_file(FILE *fp, bmpfile_t *bmp)
{
fseek(fp, 0L, SEEK_SET);
char magic[1];
fread(magic, 1, 2, fp);
printf("magic is: %c, %c\n", magic[0], magic[1]);
fread(&bmp->header, 1, 2, fp);
printf("magic is: %c, %c\n", bmp->header.magic[0], bmp->header.magic[1]);
}