读书人

运作出错Syntax error: quot;(quot; unexpecte

发布时间: 2012-11-05 09:35:12 作者: rapoo

运行出错Syntax error: "(" unexpected linux系统 开发工具anjuta
linux系统 开发工具为anjuta
编译通过 但运行老是提示出错

/home/ghgccool/桌面/expe1/expe1_1.c: 3: Syntax error: "(" unexpected

----------------------------------------------
Program exited successfully with errcode (2)
Press the Enter key to close this terminal ...


下面是程序

#include <stdio.h>
int main(){
int i, r, p1, p2, fd[2];

char buf[50], s[50];

pipe(fd);

while ((p1=fork())==-1);

if (p1==0)

{ lockf(fd[1], 1, 0);

sprintf(buf, "Child process P1 is sending messages! \n");

printf("Child process P1! \n");

write(fd[1], buf, 50);

sleep(5);

lockf(fd[1],0,0);

exit(0);

}

else

{ while ((p2=fork())==-1);

if (p2==0)

{ lockf(fd[1], 1, 0);

sprintf(buf, "Child process P2 is sending messages! \n");

printf("Child process P2! \n");

write(fd[1], buf, 50);

sleep(5);

lockf(fd[1], 0, 0);

exit(0);

}

wait(0);

if ((r=read(fd[0], s, 50))== -1) printf("cannot read pipe! \n");

else printf("%s", s);

wait(0);

if ((r=read(fd[0], s, 50))== -1) printf("cannot read pipe! \n");

else printf("%s", s);

exit(0);

}

}


[解决办法]
我用gcc编译运行没问题,只是多了隐士声明,gcc选取默认值。
syntax.c:25:3: 警告: 隐式声明与内建函数‘exit’不兼容 [默认启用]
syntax.c:47:3: 警告: 隐式声明与内建函数‘exit’不兼容 [默认启用]
syntax.c:63:3: 警告: 隐式声明与内建函数‘exit’不兼容 [默认启用]

加头文件试试
#include <stdlib.h>

读书人网 >UNIXLINUX

热点推荐