#include #include char * * split(char * line, char * seps) { char * * r = (char * *) malloc (sizeof(char *)); int size = 1, num = 0; char * s = strtok(line, seps); while (1) { if (num >= size) { int newsize = size * 2, i; char * * newr = (char * *) malloc (newsize * sizeof(char *)); for (i = 0; i < size; i += 1) newr[i] = r[i]; free(r); r = newr; size = newsize; } r[num] = s; num += 1; if (s == NULL) break; s = strtok(NULL, " \n"); } return r; } int main() { char line[100]; int i; char * * parts; fgets(line, 100, stdin); printf("the line is '%s'\n", line); parts = split(line, " \n"); for (i = 0; parts[i] != NULL; i += 1) printf("part %d = '%s'\n", i, parts[i]); printf("the line is '%s'\n", line); }