Advertisement
salmaNAS

Untitled

Oct 14th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. while ((de = readdir(dr)) != NULL)
  2. printf("%s\n", de->d_name);
  3. ........................................................
  4. char *buf;
  5. buf=(char *)malloc(100*sizeof(char));
  6. getcwd(buf,100);
  7. printf("\n %s \n",buf);
  8. .....................
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. int main()
  13. {
  14. pid_t childPID = fork();
  15.  
  16. if(childPID >0){
  17. printf("Hello world!\n");
  18.  
  19. }
  20. else if(childPID ==0)
  21. {
  22. printf("Salomaaaaa i am the child");
  23. }
  24. else {
  25. printf("An error occured!!");
  26. exit(-1);
  27. }
  28. return 0;
  29. }
  30. .........................
  31. #include<stdio.h>
  32. #include<stdlib.h>
  33. #define _GNU_SOURCE
  34. #include<string.h>
  35. #include<unistd.h>
  36.  
  37. void checkCommand( char* InputSepCommandTokens[] , int commandWithArgsFlag){
  38. if(commandWithArgsFlag==1)
  39. printf("You typed an argumantative command %s" , InputSepCommandTokens[0]);
  40. else
  41. printf("NO ARGUMENTS");
  42.  
  43. }
  44.  
  45. int main()
  46. {
  47. int commandWithArgsFlag = 0;
  48. char *InputCommand[10];
  49. char *InputSepCommandTokens[10];
  50. printf("Enter command Line: ");
  51. fgets(&InputCommand, 100, stdin);
  52.  
  53. printf("Entered command line is:%s \n", InputCommand);
  54. char space[] = " ";
  55. char *parsedInputCommand =strtok(&InputCommand,space);
  56. //char* firstToken = parsedInputCommand;
  57. //printf("first token is:%s \n", firstToken);
  58. int count=0;
  59. InputSepCommandTokens[0] =parsedInputCommand;
  60. while( (parsedInputCommand) != NULL){
  61. printf("hi:%s \n", parsedInputCommand);
  62. parsedInputCommand = strtok( NULL, space );
  63. count++;
  64. InputSepCommandTokens[count] = parsedInputCommand;
  65. }
  66.  
  67. //printf("\n Count is: %d \n\n ........ \n" , count);
  68. if(count >1) commandWithArgsFlag=1;
  69.  
  70. int i;
  71. for(i=0 ; i<count ;i++){
  72. printf("%d token is:%s \n" , (i+1) , InputSepCommandTokens[i]);
  73. }
  74.  
  75. // printf(" you just wrote:%s \n" , InputSepCommandTokens[0]);
  76. char * exitCheck[1] = {"exit"};
  77.  
  78.  
  79. // printf("ExitCheck is: %s\n...........\n" , exitCheck[0]);
  80. // printf("InputSepCommandTokens[0] is: %s\n...........\n" , InputSepCommandTokens[0]);
  81.  
  82.  
  83. if(strncmp( InputSepCommandTokens[0], exitCheck[0] , 4) == 0 ) {
  84. printf("\n...............PROGRAM HAS TERMINATED...................");
  85. abort();
  86. }
  87.  
  88. else
  89. checkCommand(InputSepCommandTokens , commandWithArgsFlag);
  90. //exit(0);
  91. //better make this a while
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement