gpt4 book ai didi

c - C中的read()和write()有什么错误?

转载 作者:太空宇宙 更新时间:2023-11-04 06:50:19 25 4
gpt4 key购买 nike

<分区>

这是一个小的C程序,用于测试客户端和服务器程序,以便客户端向客户端发送一个整数。服务器将该数字乘以 10 并将整数 * 10 返回给客户端。将整数写入 FIFO 时。到目前为止,这是我的代码:

#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

main (void)
{
int fda;
int fdb;
int number;
int outputnumber;



if((fda=open("FIFO_to_server", O_WRONLY))<0)
printf("cant open fifo to write");

if((fdb=open("FIFO_to_client", O_RDONLY))<0)
printf("cant open fifo to read");

printf("Client: Please enter an integer: ");
scanf("%d", &number);


write(fda, number, sizeof(number));
printf("\nClient: Got the number sent, now waiting for response ");
read(fdb, outputnumber, sizeof(outputnumber));
printf("\nClient: received from server %s", outputnumber);

close(fda);
close(fdb);

printf ("\nall done!\n");

}

编译后出现错误:

-bash-3.2$ gcc clientHw.c -o client
clientHw.c: In function `main':
clientHw.c:36: warning: passing arg 2 of `write' makes pointer from integer
without a cast
clientHw.c:38: warning: passing arg 2 of `read' makes pointer from integer
without a cast

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