Kob*_*obi 2 c unix file-descriptor
我想使用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
Run Code Online (Sandbox Code Playgroud)
您需要传递一个地址,因此您需要某种形式或其他形式的变量.
如果您只需要一个字符:
char c = 1;
write(fd, &c, 1);
c = 0x35;
write(fd, &c, 1);
Run Code Online (Sandbox Code Playgroud)
或使用数组(这通常更常见):
char data[2] = { 0x01, 0x35 };
write(fd, data, 2);
Run Code Online (Sandbox Code Playgroud)