#define bmpSIGNATURE 0X4D42
unsigned short Get16U(unsigned int *x)
{
unsigned short temp ;
temp = *x & (0xFFFF);
return temp;
}
unsigned int *bAddress,fdr;
void main()
{
disp_str("FILE OPEN",1,0);
disp_rw_clr(2);
bAddress = FILE_Open((void *)pUSBDevInfo, Directory[dir_cnt].FileName, RDONLY); // Read the file from USB and return start address
/* read bmp header */
pFileheader->Type = Get16U(bAddress); // save the first two bytes of bmp file data
(char*)bAddress++;
(char*)bAddress++; // increment the address by 2 bytes to reach address of "Filesize" parameter
if(pFileheader->Type == bmpSIGNATURE) // read further bytes of the FILE header and INFO header only if the file is a bitmap
{
pFileheader->FileSize = Get32U(bAddress); // save the filesize
bAddress = bAddress + 2; // increment the address by 8 bytes to reach address of "offset" parameter
pFileheader->PxOffset = Get32U(bAddress); // save the offset
bAddress++; // increment the address by 4 bytes to reach address of "info header size" parameter
}
}
好的,这是我编写的代码的一部分,用于在从USB驱动器打开后读取bmp文件头。在读取bmp部分中,我想将无符号整数指针bAddress
递增一个字节,即作为字符指针((char*)bAddress++)
,以便我将达到我想要读取的数据。现在(如果我将指针递增为(bAdress++)
),我将得到错误的数据,因为地址将增加4个字节)。如果我使用(char*)bAddress++;