Advertisement
Guest User

Untitled

a guest
Nov 12th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2. #include <assert.h>
  3. #include <dirent.h>
  4. #include <errno.h>
  5. #include <fcntl.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/resource.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <sys/wait.h>
  13. #include <termios.h>
  14. #include <unistd.h>
  15.  
  16. char ** split(char * s, char * separator) {
  17. char ** words = malloc(sizeof(char *));
  18. int i = 0;
  19. char * word = strtok(strdup(s), separator);
  20. while (word) {
  21. words = realloc(words, sizeof(char *) * (i + 1));
  22. words[i] = malloc(strlen(word) + 1);
  23. strcpy(words[i++], word);
  24. word = strtok(NULL, separator);
  25. }
  26. words = realloc(words, sizeof(char *) * (i + 1));
  27. words[i] = NULL;
  28. return words;
  29. }
  30.  
  31.  
  32. int main(int argc, char * argv[]) {
  33. char ** p = split("a b c d e f", " ");
  34. while(*p++);
  35. printf("%i", strcmp(*--p, "&"));
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement