/* ex: set ts=8 noet: */ /* Copyright 2007 Ryan "pizza" Flynn */ /* Mon Sep 17 10:43:41 EDT 2007 */ #include #include #include static void nextword(const char *); /** * find next word, call self, print word */ static void nextword(const char *pos) { const char *start = pos, *end; if (!*pos) return; while (*start == ' ') start++; end = start + 1; while (*end && *end != ' ') end++; nextword(end); printf("%.*s ", (int)(end - start), start); } int main() { char buf[80]; printf("Enter string: "); fflush(stdout); if (NULL == fgets(buf, sizeof buf, stdin)) { perror("fgets"); exit(EXIT_FAILURE); } strcspn(buf, "\n")[buf] = '\0'; nextword(buf); printf("\n"); return 0; }