Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <dirent.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/resource.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <termios.h>
- #include <unistd.h>
- char ** split(char * s, char * separator) {
- char ** words = malloc(sizeof(char *));
- int i = 0;
- char * word = strtok(strdup(s), separator);
- while (word) {
- words = realloc(words, sizeof(char *) * (i + 1));
- words[i] = malloc(strlen(word) + 1);
- strcpy(words[i++], word);
- word = strtok(NULL, separator);
- }
- words = realloc(words, sizeof(char *) * (i + 1));
- words[i] = NULL;
- return words;
- }
- int main(int argc, char * argv[]) {
- char ** p = split("a b c d e f", " ");
- while(*p++);
- printf("%i", strcmp(*--p, "&"));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement