
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 展开
#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 展开
3个回答
展开全部
括号不匹配,,,,在检查下括号
修改后为:
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);
}
修改后为:
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);
}
展开全部
else if(pid==0)的后面加一个{左大括号
括号要成对出现的。。
括号要成对出现的。。
更多追问追答
追问
修改之后又出现 undefined reference to `excel'
追答
没有这个函数,不知你调用的这个函数的功能是什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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);
}
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下的头文件吗?
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询