无法正确使用 fwrite
Unable to use fwrite properly
我不知道如何在这里使用 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
用于写入文件,但你想将内存设置为零,这不是一回事。
通过这行代码,整个 triple
结构被设置为零。
memset(&triple, 0, sizeof triple);
应打开 fwrite 的第四个参数以写入 FILE
给零导致异常
FILE * aFileYouWrite = fopen("afilename.xyz","wb");
memset(&triple, 0, sizeof triple);
fwrite(&triple.rgbtRed, sizeof(uint8_t), 1, aFileYouWrite );
我不知道如何在这里使用 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
用于写入文件,但你想将内存设置为零,这不是一回事。
通过这行代码,整个 triple
结构被设置为零。
memset(&triple, 0, sizeof triple);
应打开 fwrite 的第四个参数以写入 FILE
给零导致异常
FILE * aFileYouWrite = fopen("afilename.xyz","wb");
memset(&triple, 0, sizeof triple);
fwrite(&triple.rgbtRed, sizeof(uint8_t), 1, aFileYouWrite );