通过管道在进程之间传递多个 int
我是 C 新手。我的问题与语法更相关。我知道如何使用管道通过管道发送整数。
写入管道
int n = 50;
write(fd[1], &n, sizeof(n));
从管道读取
int n;
read(fd[0], &n, sizeof(n));
但我想知道如何修改管道以发送 2 个整数?我尝试了下面的代码,但没有成功。
写入管道
int n1 = 50, n2 = 30;
write(fd[1], &n1 &n2, sizeof(n1)+sizeof(n2));
从管道读取
int n1, n2;
read(fd[0], &n1 &n2, sizeof(n1)+sizeof(n2));
谢谢!
I'm new to C. My question is more related to syntax. I know how to use pipe to send integer over the pipe.
writing to the pipe
int n = 50;
write(fd[1], &n, sizeof(n));
reading from the pipe
int n;
read(fd[0], &n, sizeof(n));
But I want to know how do i modify the pipe to send 2 integers? I tried the code below but it didn't work.
writing to the pipe
int n1 = 50, n2 = 30;
write(fd[1], &n1 &n2, sizeof(n1)+sizeof(n2));
reading from the pipe
int n1, n2;
read(fd[0], &n1 &n2, sizeof(n1)+sizeof(n2));
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论