小编Eng*_*ine的帖子

为什么我不能运行这个 C 程序?

我正在尝试运行我的第一个“进程”程序,但出现以下错误:

./fork.c: line 4: syntax error near unexpected token `('
./fork.c: line 4: `int main()'
Run Code Online (Sandbox Code Playgroud)

我很确定代码是正确的:

 #include <sys/types.h>
 #include <stdio.h>
 int main() {
     pid_t pid;
     printf("Hello fork()\n");
     switch(pid=fork())  {
         case -1: printf("Error by fork().....\n"); exit(0);
         case 0: printf("I'm the child process \n"); break;
         default: printf("I'm the dad \n"); break;
     }
  exit(0);
}
Run Code Online (Sandbox Code Playgroud)

怎么了?

c compiler

12
推荐指数
2
解决办法
7234
查看次数

标签 统计

c ×1

compiler ×1