/* word_stats.c Author: Murray Saul Date: March 15, 2008 Purpose: To demonstrate strlen, strcomp, and strcpy functions */ void showStats( char word[]); void clearInput(); #include #include #define WORD_SIZE 40 + 1 main() { char word[WORD_SIZE]; printf ("Enter a single word: "); scanf("%s", word); clearInput(); showStats(word); } /* end of main program */ void clearInput() { while (getchar() != '\n') ; } /* end of clearInput() function */ void showStats( char word[]) { char upper_word[WORD_SIZE]; int i; printf ("STATICS REPORT for the word \"%s\":\n\n", word); printf ("Number of characters of \"%s\": %d\n", word, strlen(word)); strcpy(upper_word, word); for (i=0; i < strlen(upper_word); i++) upper_word[i] = toupper(upper_word[i]); printf ("Here is \"%s\" capitalized: %s\n", word, upper_word); printf ("Do words \"%s\" and \"%s\" match? ", word, upper_word); if ( strcmp(word, upper_word) != 0 ) printf ("NO\n\n"); else printf ("YES\n\n"); } /* End of showStats() function */