c语言错误 expected identifier or '(' before 'else‘

#include<unistd.h>#include<sys/wait.h>#include<stdio.h>#include<stdlib.h>intmain(){pi... #include<unistd.h>
#include<sys/wait.h>
#include<stdio.h>
#include<stdlib.h>
int main(){
pid_t pid;
int result;
pid=fork();
if(pid<0)
printf("fork error");
else if(pid == 0)
printf("new program.\n");
excel("/root/fork.out","fork.out",0);
exit(0);
}
else
{
int e=waitpid(pid,&result,0);
printf("Child process PID:%d.\n",e);
exit(0);
}
}

22.c:16:2: 错误:expected identifier or ‘(’ before ‘else’
22.c:22:1: 错误:expected identifier or ‘(’ before ‘}’ token
展开
 我来答
a1012144015
2016-01-09 · TA获得超过6416个赞
知道大有可为答主
回答量:9038
采纳率:40%
帮助的人:1447万
展开全部
括号不匹配,,,,在检查下括号
修改后为:
if(pid<0)
printf("fork error");
else if(pid == 0){ //这里少了一个 “{”吧
printf("new program.\n");
excel("/root/fork.out","fork.out",0);
exit(0);
}
else
{
int e=waitpid(pid,&result,0);
printf("Child process PID:%d.\n",e);
exit(0);
}
wchyumo2011
2015-07-02 · TA获得超过2万个赞
知道大有可为答主
回答量:5810
采纳率:79%
帮助的人:3076万
展开全部
else if(pid==0)的后面加一个{左大括号
括号要成对出现的。。
更多追问追答
追问
修改之后又出现  undefined reference to `excel'
追答
没有这个函数,不知你调用的这个函数的功能是什么?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
iS谁在看YoU
推荐于2018-02-26 · TA获得超过367个赞
知道小有建树答主
回答量:253
采纳率:90%
帮助的人:195万
展开全部
if(pid<0)
printf("fork error");
else if(pid == 0){ //这里少了一个 “{”吧
printf("new program.\n");
excel("/root/fork.out","fork.out",0);
exit(0);
}
else
{
int e=waitpid(pid,&result,0);
printf("Child process PID:%d.\n",e);
exit(0);
}
追问
修改之后又出现  undefined reference to `excel'
追答
excel函数是不是可以使用?
unistd.h是window下的头文件吗?
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式