免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1396 | 回复: 3
打印 上一主题 下一主题

管道通信的程序老编译如下,期待高手解决! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-05-14 09:27 |只看该作者 |倒序浏览
一个管道通信的程序,参考程序如下:
#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是什么意思?老编译不过就没信心啦!麻烦高手给个答案阿!小弟先谢了!

论坛徽章:
0
2 [报告]
发表于 2006-05-14 09:29 |只看该作者
因为是新手,刚学编程,如果问题问的肤浅请高手们不要见笑啊!你们不也是从菜鸟一步步成长起来的吗?要助人为乐嘛!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2006-05-14 12:56 |只看该作者
估计是” 这些中文字符的”的原因.换成" 就好了.

论坛徽章:
0
4 [报告]
发表于 2006-05-14 16:17 |只看该作者
谢谢斑竹,试一下!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP