gpt4 book ai didi

c - 如何将struct char写入文件

转载 作者:行者123 更新时间:2023-11-30 21:39:14 24 4
gpt4 key购买 nike

typedef struct {
const char *name;
const unsigned char *data;
const unsigned int size;
} Assembly;

void test(const Assembly **assemblies);

void test(const Assembly ** assemblies)
{

//i want to print assemblies to a txt file.
//like this:
//name->XXX
//data->DDD
//size->YYY
}

int main()
{
test(bundled);
return 0;
}

我刚开始学习C,这个任务太难了。 我不知道该怎么做。请帮助我。谢谢!

我尝试这样做: enter image description here

问题是:

对于每个 char 二进制数组,‘144’更改为 -122

“255”更改为-1。

就像上图一样!

如何获取数据{77, 90, 144, 0, 3, 0, 0, 0, 4, 0, 0, 0, 255, 255} 并将其写入txt文件。

最佳答案

嗯,它是 144.. 你写为 unsigned char (从 0 到 255 ),但看起来你读为 char (从 -128 到 127 )。144 作为无符号字符是[1001000]b。-112,因为 char 是 [10010000]b。你的代码没有任何问题。

关于c - 如何将struct char写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37790508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com