gpt4 book ai didi

c - 使用写入将整数写入文件描述符?

转载 作者:行者123 更新时间:2023-12-04 12:05:51 26 4
gpt4 key购买 nike

我想使用 write (http://linux.about.com/library/cmd/blcmdl2_write.htm) 将整数 1 写入第一个字节,将 0x35 写入文件描述符的第二个字节,但我得到以下信息当我尝试以下操作时发出警告:

write(fd, 1, 1);
write(fd, 0x35, 1);


source.c:29: warning: passing argument 2 of ‘write’ makes pointer from integer without a cast
source.c:30: warning: passing argument 2 of ‘write’ makes pointer from integer without a cast

最佳答案

您需要传递一个地址,因此您需要某种形式的变量。

如果你只需要一个字符:

char c = 1;
write(fd, &c, 1);
c = 0x35;
write(fd, &c, 1);

或者使用数组(这个一般比较常见):

char data[2] = { 0x01, 0x35 };
write(fd, data, 2);

关于c - 使用写入将整数写入文件描述符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9597073/

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