#include #include #include void cap_all(char* text){ for(char *i = text; *i; i++) *i = toupper(*i); } void lower_all(char* text){ for(char *i = text; *i; i++) *i = tolower(*i); } void remove_space(char* text){ for(char *i = text; *i; i++) if(*i == ' ') *i = '_'; } void apply_and_print(char* text, void (*to_apply)(char*)){ to_apply(text); puts(text); } void (*return_cycle())(char*){ void (*functions[])(char*) = {cap_all, lower_all, remove_space}; size_t nfun = sizeof(functions) / sizeof(functions[0]); static int current = 0; current++; if(current >= nfun) current = 0; return functions[current]; } int main(){ char story[] = "There was a moose in the living room. It went ..."; void (*my_name_that_I_like_better)(char*); // Maybe we would have expected this instead: // void (*)(char*) my_name_that_I_like_better; my_name_that_I_like_better = lower_all; my_name_that_I_like_better(story); puts(story); my_name_that_I_like_better = cap_all; my_name_that_I_like_better(story); puts(story); apply_and_print(story, cap_all); apply_and_print(story, lower_all); apply_and_print(story, remove_space); char another_story[] = "The mouse had spectacles that were cracked. It ..."; return_cycle()(another_story); puts(another_story); return_cycle()(another_story); puts(another_story); return_cycle()(another_story); puts(another_story); return_cycle()(another_story); puts(another_story); return_cycle()(another_story); puts(another_story); return 0; }