Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define BUFSIZE 10000
  5. int space;
  6. char** createArray(char *line) {
  7. int len_line = strlen(line);
  8. char **wordArray = NULL;
  9. if(len_line > 1){
  10. char *token = strtok(line, " ");
  11. space = 0;
  12. while (token) {
  13. wordArray = realloc(wordArray, sizeof(char*)*++space);
  14. wordArray[space-1] = token;
  15. token = strtok(NULL, " ");
  16. }
  17. }
  18. return wordArray;
  19. }
  20.  
  21.  
  22. int main(int argc, const char* argv[]) {
  23. char line[BUFSIZE];
  24. while (1) {
  25. printf("%sn", ">");
  26. fgets(line, BUFSIZE, stdin);
  27. char** l = createArray(line);
  28.  
  29. if (l) {
  30. /*why instaed of zero, when l[0]
  31. /*equals quit, strcmp() returns 10?*/
  32. printf("%dn", strcmp(l[0], "exit"));
  33. if(strcmp(l[0], "exit")==10) {
  34. exit(0);
  35. }
  36. else if(fork() == 0) {
  37. execv(l[0], l);
  38. printf("%sn", "Error!");
  39. }
  40. }
  41. }
  42. return 1;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement