当我尝试在Xcode中构建代码时,我遇到了问题 朋友,我是C的noobie,我需要一些帮助
这是我的 main.c 文件
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main (int argc, char *argv[])
{
pid_t pid;
int status;
if (argc < 2) {
printf ("Something goes wrong!\n");
return 1;
}
for (;;) {
pid = fork ();
if (pid == -1) {
perror ("fork");
exit (1);
}
if (pid == 0) {
execvp (argv[1], &argv[1]);
} else {
wait (&status);
if (WIFEXITED (status))
{
printf ("%s exited with return code %d\n",
argv[1], WEXITSTATUS (status));
if (WEXITSTATUS (status) != 0)
}
else if (WIFSIGNALED(status))
{
printf ("%s terminated by signal number %d\n",
argv[1], WTERMSIG (status));
}
/* we want to give time to user for read output of program */
sleep (1);
}
}
return 0;
}
此行之后
if (WEXITSTATUS (status) != 0)
我有一个解析问题预期声明 任何人都可以告诉我为什么错了? 谢谢。
答案 0 :(得分:0)
只需更改此
printf ("%s exited with return code %d\n",
argv[1], WEXITSTATUS (status));
if (WEXITSTATUS (status) != 0)
到这个
printf ("%s exited with return code %d\n",
argv[1], WEXITSTATUS (status));
if (WEXITSTATUS (status) != 0);
或
printf ("%s exited with return code %d\n",
argv[1], WEXITSTATUS (status));
if (WEXITSTATUS (status) != 0) {}