fork download
  1. void work(char * line)
  2. {
  3. if(check_cd(line))
  4. return;
  5. strcpy(line , buf);
  6. pid_t pid = fork();
  7. int status;
  8. int bol_flag = back_ground_check(line);
  9. if(pid==0) // child
  10. {
  11. char *argo [100];
  12. char *paths = getenv("PATH" );
  13. char *token = strtok(paths , ":");
  14. if(strstr(line, "echo") != NULL) {
  15. parse_echo(line , argo);
  16. }
  17. else
  18. parse(line , argo);
  19. if(execv (*argo , argo)>0)
  20. return;
  21. do
  22. {
  23. char temp[100];
  24. strcpy(temp , token);
  25. char temp2[50];
  26. strcpy(temp2, "/");
  27. strcat(temp2 , *argo);
  28. strcat(temp , temp2);
  29. if(execv(temp, argo) >0)
  30. break;
  31. token = strtok(NULL , ":");
  32. }while(token!= NULL);
  33. exit(1);
  34. }
  35. else if(pid <0)
  36. {
  37. exit(1);
  38. }
  39. else
  40. {
  41. if(!bol_flag)
  42. while (wait(&status) != pid) ;
  43. }
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'work':
prog.c:3:8: warning: implicit declaration of function 'check_cd' [-Wimplicit-function-declaration]
     if(check_cd(line))
        ^
prog.c:5:5: warning: implicit declaration of function 'strcpy' [-Wimplicit-function-declaration]
     strcpy(line , buf);
     ^
prog.c:5:5: warning: incompatible implicit declaration of built-in function 'strcpy'
prog.c:5:5: note: include '<string.h>' or provide a declaration of 'strcpy'
prog.c:5:19: error: 'buf' undeclared (first use in this function)
     strcpy(line , buf);
                   ^
prog.c:5:19: note: each undeclared identifier is reported only once for each function it appears in
prog.c:6:5: error: unknown type name 'pid_t'
     pid_t pid = fork();
     ^
prog.c:6:17: warning: implicit declaration of function 'fork' [-Wimplicit-function-declaration]
     pid_t pid = fork();
                 ^
prog.c:8:20: warning: implicit declaration of function 'back_ground_check' [-Wimplicit-function-declaration]
     int bol_flag = back_ground_check(line);
                    ^
prog.c:12:23: warning: implicit declaration of function 'getenv' [-Wimplicit-function-declaration]
         char *paths = getenv("PATH" );
                       ^
prog.c:12:23: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
prog.c:13:23: warning: implicit declaration of function 'strtok' [-Wimplicit-function-declaration]
         char *token = strtok(paths , ":");
                       ^
prog.c:13:23: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
prog.c:14:12: warning: implicit declaration of function 'strstr' [-Wimplicit-function-declaration]
         if(strstr(line, "echo") != NULL) {
            ^
prog.c:14:12: warning: incompatible implicit declaration of built-in function 'strstr'
prog.c:14:12: note: include '<string.h>' or provide a declaration of 'strstr'
prog.c:14:36: error: 'NULL' undeclared (first use in this function)
         if(strstr(line, "echo") != NULL) {
                                    ^
prog.c:15:13: warning: implicit declaration of function 'parse_echo' [-Wimplicit-function-declaration]
             parse_echo(line , argo);
             ^
prog.c:18:13: warning: implicit declaration of function 'parse' [-Wimplicit-function-declaration]
             parse(line , argo);
             ^
prog.c:19:12: warning: implicit declaration of function 'execv' [-Wimplicit-function-declaration]
         if(execv (*argo , argo)>0)
            ^
prog.c:27:13: warning: implicit declaration of function 'strcat' [-Wimplicit-function-declaration]
             strcat(temp2 , *argo);
             ^
prog.c:27:13: warning: incompatible implicit declaration of built-in function 'strcat'
prog.c:27:13: note: include '<string.h>' or provide a declaration of 'strcat'
prog.c:33:9: warning: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
         exit(1);
         ^
prog.c:33:9: warning: incompatible implicit declaration of built-in function 'exit'
prog.c:33:9: note: include '<stdlib.h>' or provide a declaration of 'exit'
prog.c:37:9: warning: incompatible implicit declaration of built-in function 'exit'
         exit(1);
         ^
prog.c:37:9: note: include '<stdlib.h>' or provide a declaration of 'exit'
prog.c:42:20: warning: implicit declaration of function 'wait' [-Wimplicit-function-declaration]
             while (wait(&status) != pid) ;
                    ^
stdout
Standard output is empty