Pointers 从BM读取数据
好的,这是我写的代码的一部分,在从usb驱动器打开bmp文件头后读取它。在读取bmp部分,我想将无符号整数指针bAddress递增一个字节,即作为char指针char*bAddress++,这样我就可以访问我想要读取的数据。现在,如果我将指针作为bAdress++递增,我将到达错误的数据,因为地址将递增4个字节。使用char*bAddress++,我不知道我做得对还是错 为什么要声明非指针的unsigned int bAddress?这是你的代码还是类似的东西?对不起,我忘了写这只是我代码的一部分Pointers 从BM读取数据,pointers,bitmap,casting,embedded,post-increment,Pointers,Bitmap,Casting,Embedded,Post Increment,好的,这是我写的代码的一部分,在从usb驱动器打开bmp文件头后读取它。在读取bmp部分,我想将无符号整数指针bAddress递增一个字节,即作为char指针char*bAddress++,这样我就可以访问我想要读取的数据。现在,如果我将指针作为bAdress++递增,我将到达错误的数据,因为地址将递增4个字节。使用char*bAddress++,我不知道我做得对还是错 为什么要声明非指针的unsigned int bAddress?这是你的代码还是类似的东西?对不起,我忘了写这只是我代码的一部
#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
}
}