这是一个小的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
答案 0 :(得分:3)
您必须像这样传递变量的地址:
write(fda, &number, sizeof(number));
...
read(fdb, &outputnumber, sizeof(outputnumber));