- 论坛徽章:
- 0
|
一个管道通信的程序 ,参考程序如下:
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
int p1,p2;
main()
{
int fd[2];
char OutPipe[100],InPipe[100];
pipe(fd);
while ((p1==fork())==-1);/*创建子进程P1*/
if (p1==0)
{
lockf(fd[1],1,0);
sprintf(OutPipe,”child 1 process is sending message!”);
write(fd[1],OutPipe,50);
sleep(5);
lockf(fd[1],0,0);
exit(0);
}
else
{
while ((p2==fork())==-1);/*创建另一个子进程P2*/
if (p2==0)
{
lockf(fd[1],1,0);
sprintf(OutPipe,”child 2 process is sending message!”);
write(fd[1],OutPipe,50);
sleep(5);
lockf(fd[1],0,0);
exit(0);
}
else
{
wait(0);
read(fd[0],InPipe,50);
printf(“%s\n”,InPipe);
wait(0);
read(fd[0],InPipe,50);
printf(“%s\n”,InPipe);
xit(0);
}
}
}
在RED hat下用GCC编译确出现多处错误,真的烦躁!错误如下:
[root@linux 实验]# gcc -o file file.c
file.c:5: stray '\302' in program
file.c:5: stray '\240' in program
file.c: In function `main':
file.c:11: stray '\357' in program
file.c:11: stray '\274' in program
file.c:11: stray '\233' in program
file.c:15: stray '\342' in program
file.c:15: stray '\200' in program
file.c:15: stray '\235' in program
file.c:15: `child' undeclared (first use in this function)
file.c:15: (Each undeclared identifier is reported only once
file.c:15: for each function it appears in.)
file.c:15: parse error before numeric constant
file.c:15: stray '\342' in program
file.c:15: stray '\200' in program
file.c:15: stray '\235' in program
file.c:23: stray '\357' in program
file.c:23: stray '\274' in program
file.c:23: stray '\233' in program
file.c:27: stray '\342' in program
file.c:27: stray '\200' in program
file.c:27: stray '\235' in program
file.c:27: parse error before numeric constant
file.c:27: stray '\342' in program
file.c:27: stray '\200' in program
file.c:27: stray '\235' in program
file.c:37: stray '\342' in program
file.c:37: stray '\200' in program
file.c:37: stray '\234' in program
file.c:37: parse error before '%' token
file.c:37: stray '\' in program
file.c:37: stray '\342' in program
file.c:37: stray '\200' in program
file.c:37: stray '\235' in program
file.c:40: stray '\342' in program
file.c:40: stray '\200' in program
file.c:40: stray '\234' in program
file.c:40: parse error before '%' token
file.c:40: stray '\' in program
file.c:40: stray '\342' in program
file.c:40: stray '\200' in program
file.c:40: stray '\235' in program
请问file.c:40: stray '\235' in program是什么意思?老编译不过就没信心啦!麻烦高手给个答案阿!小弟先谢了! |
|