C 我被这段代码困住了,对文件结构和fopen函数有疑问
这是我的密码。 我在这段代码中的主要目的是读取bmp文件头。我想声明一个指针,它将保存由fopen()创建的缓冲区的起始地址。我将使用该起始地址从缓冲区读取数据。 我在ARM控制器中使用此代码。 这不是完整的代码 在梅因之前,我已经宣布全球范围内的不良着装为-C 我被这段代码困住了,对文件结构和fopen函数有疑问,c,pointers,arm,fopen,bitmapimage,C,Pointers,Arm,Fopen,Bitmapimage,这是我的密码。 我在这段代码中的主要目的是读取bmp文件头。我想声明一个指针,它将保存由fopen()创建的缓冲区的起始地址。我将使用该起始地址从缓冲区读取数据。 我在ARM控制器中使用此代码。 这不是完整的代码 在梅因之前,我已经宣布全球范围内的不良着装为- typedef struct tagFileheader { unsigned short Type; // 00h File Type Identifier to check if
typedef struct tagFileheader
{
unsigned short Type; // 00h File Type Identifier to check if the file is bmp or not
unsigned int FileSize; // 02h Size of bmp file No.of bytes of the bitmap file
unsigned int PxOffset; // 0Ah Offset to bitmap pixel data
}Fileheader;
Fileheader filehdr;
Fileheader *pFileheader = &filehdr;
unsigned short Get16U(unsigned int *x)
{
unsigned short temp;
temp = *x & (0xFFFF);
return temp;
}
unsigned int Get32U(unsigned int *x)
{
unsigned int temp;
temp = *x ;
return temp;
}
int Get32(unsigned int *x)
{
int temp;
temp = *x ;
return temp;
}
void main()
{
unsigned int headersize,i ;
bAddress = fopen("D:/Tapan/Projects/Jacquard/BMP/03Body.bmp","rb"); // open the file and send the start address of its memory location
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
}
}
当我编译代码时,我得到以下错误——“int”类型的值不能分配给“unsigned int*”类型的实体
现在我的问题是,我的指针声明正确吗?
我见过这个文件被用来为fopen()声明指针变量
我应该如何在这里使用文件。我应该如何声明文件的结构?我认为以文本模式读取bmp文件不是一个好主意。使用二进制模式
“rb”
(而不是“r”
)和fread()
函数,并且不要直接更改指向文件结构的指针以及文件字段中的数据。使用
unsigned int *bAddress
不会将文件*
移动两个字符。事实上,它会使坏衣服
不可用。您需要的是:
(char*)bAddress++;
(char*)bAddress++;
然而,我感觉更改这两行并不能解决您的问题。您显然不知道如何使用文件*
执行I/O。在实际程序中使用它之前,您需要花一些时间阅读使用文件*
文件I/O的工作原理
您可以从。开始学习教程,更不用说fopen(…)不会编译,因为它将返回一个
文件*
,而不是一个char指针,它是FILE@tapanchawda,则文件的结构取决于实现。语言没有指定它。它只指定如何使用文件*
。因此,在我的例子中,我应该如何声明文件结构。@tapanchawda,这是这是另一个迹象,表明您需要更加了解使用C的文件I/O。
fgetc(bAddress);
fgetc(bAddress);