fork () ошибка программы программы запускается с помощью putty [duplicate]

Этот вопрос уже имеет ответ здесь: как исправить ошибки компиляции, которые упоминают & ldquo; stray '\ 342' & rdquo; и & ldquo; бродячие '\ 200' & rdquo ;? [closed] 3 ответа
#include<stdio.h> #include<sys/wait.h> int main() { int p1,p2; p1=fork(); if(p1==-1) { printf(“Error”); } else { printf(“Parent is %d, Child is %d n”,getppid(),getpid()); } p2=fork(); printf(“Parent is %d, Child is %d n”,getppid(),getpid()); return 0; abcd.c: In function ‘main’: abcd.c:7:4: warning: implicit declaration of function ‘fork’ [-Wimplicit-function-declaration] p1=fork(); ^ abcd.c:10:1: error: stray ‘\342’ in program printf(“Error”); ^ abcd.c:10:1: error: stray ‘\200’ in program abcd.c:10:1: error: stray ‘\234’ in program abcd.c:10:1: error: stray ‘\342’ in program abcd.c:10:1: error: stray ‘\200’ in program abcd.c:10:1: error: stray ‘\235’ in program abcd.c:10:11: error: ‘Error’ undeclared (first use in this function) printf(“Error”); ^ abcd.c:10:11: note: each undeclared identifier is reported only once for each function it appears in abcd.c:14:1: error: stray ‘\342’ in program printf(“Parent is %d, Child is %d n”,getppid(),getpid()); ^ abcd.c:14:1: error: stray ‘\200’ in program abcd.c:14:1: error: stray ‘\234’ in program abcd.c:14:11: error: ‘Parent’ undeclared (first use in this function) printf(“Parent is %d, Child is %d n”,getppid(),getpid()); ^ abcd.c:14:18: error: expected ‘)’ before ‘is’ printf(“Parent is %d, Child is %d n”,getppid(),getpid()); ^ abcd.c:14:18: error: stray ‘\342’ in program abcd.c:14:18: error: stray ‘\200’ in program abcd.c:14:18: error: stray ‘\235’ in program abcd.c:17:1: error: stray ‘\342’ in program printf(“Parent is %d, Child is %d n”,getppid(),getpid()); ^ abcd.c:17:1: error: stray ‘\200’ in program abcd.c:17:1: error: stray ‘\234’ in program abcd.c:17:18: error: expected ‘)’ before ‘is’ printf(“Parent is %d, Child is %d n”,getppid(),getpid()); ^ abcd.c:17:18: error: stray ‘\342’ in program abcd.c:17:18: error: stray ‘\200’ in program abcd.c:17:18: error: stray ‘\235’ in program
-2
задан 20 July 2017 в 13:28

2 ответа

Вам нужно добавить

#include <unistd.h>

, чтобы использовать fork, изменить все “ на " и добавить конец } в конец:

#include<stdio.h> #include<sys/wait.h> #include <unistd.h> int main() { int p1,p2; p1=fork(); if(p1==-1) { printf("Error"); } else { printf("Parent is %d, Child is %d n",getppid(),getpid()); } p2=fork(); printf("Parent is %d, Child is %d n",getppid(),getpid()); return 0; }
2
ответ дан 18 July 2018 в 09:59

Вам нужно добавить

#include <unistd.h>

, чтобы использовать fork, изменить все “ на " и добавить конец } в конец:

#include<stdio.h> #include<sys/wait.h> #include <unistd.h> int main() { int p1,p2; p1=fork(); if(p1==-1) { printf("Error"); } else { printf("Parent is %d, Child is %d n",getppid(),getpid()); } p2=fork(); printf("Parent is %d, Child is %d n",getppid(),getpid()); return 0; }
2
ответ дан 24 July 2018 в 19:29
  • 1
    Я использовал заголовочный файл #include & lt; unistd.h & gt; но нить не решена, возможно ли, что этот заголовок не доступен в моем компьютере, как я проверю этот файл, или нет – Dushyant Chawda 21 July 2017 в 08:32
  • 2
    Он находится в пакете libc6-dev – Florian Diesch 21 July 2017 в 13:05

Другие вопросы по тегам:

Похожие вопросы: