#include #include bool alphabetic (const char c) { if((c >= 'a' && c<= 'z') || (c>= 'A' && c <= 'Z') ||(c >= '0' && c<='9') || c == '\t' || c =='\n' || c == ' ' ||c == '-') return true; else return false; } void readline (char buffer[]) { char character; int i=0; do{ character = getchar(); buffer[i] = character; ++i; } while (character !='\n'); buffer[i-1] = '\0'; } int countwords (const char string[]) { int i, lettercount = 0; bool looking_for_word = true, alphabetic (const char c); for (i=0; string[i] != '\0'; ++i) if(alphabetic(string[i])) { if(looking_for_word) { ++lettercount; looking_for_word=true; } } else looking_for_word = true; return lettercount; } int main (void) { char text[81]; int totalwords = 0; int countwords ( const char string[]); void readline (char buffer[]); bool endoftext = false; printf("Type in your text. \n"); printf("When you are done, press 'RETURN'. \n \n"); while ( ! endoftext) { readline(text); if(text[0] == '\0') endoftext = true; else totalwords += countwords(text); } printf("\n There are %i letters in the above text. \n",totalwords); return 0; }