# include # include // // Program 10.7, Stephen Kochan, Programming in C. // int main ( void ); bool alphabetic ( const char c ); int countWords ( const char string[] ); int main ( void ) { const char text1[] = "Well, here goes."; const char text2[] = "And here we go... again."; printf ( "%s - words = %i.\n", text1, countWords ( text1 ) ); printf ( "%s - words = %i.\n", text2, countWords ( text2 ) ); return 0; } bool alphabetic ( const char c ) { bool value; if ( ( 'a' <= c && c <= 'z' ) || ( 'A' <= c && c <= 'Z' ) ) { value = true; } else { value = false; } return value; } int countWords ( const char string[] ) { int i, wordCount = 0; bool lookingForWord = true; for ( i = 0; string[i] != '\0'; i++ ) { if ( alphabetic ( string[i] ) ) { if ( lookingForWord ) { wordCount = wordCount + 1; lookingForWord = false; } } else { lookingForWord = true; } } return wordCount; }