我无法弄清楚如何在这里使用 fwrite。我遇到了段错误。有没有其他方法可以将 0x00 写入 rgbtRed、rgbtBlue 和 rgbtGreen?我在网上查了一下,但找不到正确的方法。
#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef uint8_t BYTE;
typedef struct
{
BYTE rgbtBlue;
BYTE rgbtGreen;
BYTE rgbtRed;
} __attribute__((__packed__))
RGBTRIPLE;
int main (void)
{
RGBTRIPLE triple;
/*code which opens a bmp file, copies it and exports it to another
file based on the changes which I ask it.
I'm trying to set R's (of RGB) value to 0 to see if that solves
the problem. I'm trying to figure out how to set the value to 0*/
fwrite(&triple.rgbtRed, sizeof(uint8_t), 1, 0x00);
}
最佳答案
fwrite
用于写入文件,但您希望将内存设置为零,这并不完全相同。
通过这行代码,整个三重
结构被设置为零。
memset(&triple, 0, sizeof triple);
关于c - 无法正确使用fwrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50679782/