如何使用fwrite写入数据0xf0f0f0f0
我需要使用 fwrite 将分隔符 = 0xf0f0f0f0 写入二进制文件。需要以这样的方式完成:在 UNIX 上的 xxd 中查看时,0xf0f0f0f0 出现在文件的开头。我目前正在这样做,
unsigned int delim[1];
delim[1] = 0xf0f0f0f0;
fwrite(delim, 4, 1, destination);
但它显然不起作用,因为 xxd 在文件开头显示了这一点:
0000000: 90c9 49ac
I need to use fwrite to write a delimiter = 0xf0f0f0f0 to a binary file. It needs to be done in such a way that 0xf0f0f0f0 appears at the beginning of the file when viewed in xxd on UNIX. I'm currently doing it this way,
unsigned int delim[1];
delim[1] = 0xf0f0f0f0;
fwrite(delim, 4, 1, destination);
But it's clearly not working since xxd is showing this at the beginning of the file:
0000000: 90c9 49ac
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能应该是
或者至少使用
delim[0]
因为数组索引从 0 开始。Probably should be
Or at least use
delim[0]
since array indexing starts at 0.这是:
是一个包含一个元素的数组。
this:
指的是单元素数组中的第二个元素,这不是正确的代码。
如果您想将某些内容放入单元素数组中,请将
delim[1]
更改为delim[0]
。This:
is an array containing one element.
This:
refers to the second element in a single-element array, which is not correct code.
Change
delim[1]
todelim[0]
, if you want to put something in your single-element array.