-: 0:Source:count_words.c -: 0:Graph:count_words.gcno -: 0:Data:count_words.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include -: 2:#include -: 3:#include -: 4:#include "count_words.h" -: 5: -: 6:/* count_words.c -: 7: * -: 8: * This is included as a simple example of code you could test using miniunit. Use if you -: 9: * find it helpful. Feel free to modify any way you like. You will not turn this in. -: 10: * -: 11: * Two bugs were intentionally planted to make testing this code more interesting: -: 12: * ∙ count_words(…) does not count an apostrophe ("'") or hyphen ("-") as part of a word. -: 13: * ∙ The helper _is_letter(…) does not treat "a", "A", "z", and "Z" as letters. -: 14: * -: 15: * More about this code: -: 16: * ∙ bool is a type that can be true or false. It requires #include . -: 17: */ -: 18: -: 19:bool _is_letter(char ch); // helper -: 20: 1: 21:int count_words(const char* words) { 1: 22: int num_words = 0; 1: 23: bool in_word = false; 21: 24: for(int i=0; words[i] != '\0'; i++) { 20: 25: if(! in_word && _is_letter(words[i])) { 4: 26: num_words++; 4: 27: in_word = true; -: 28: } 16: 29: else if(in_word && ! _is_letter(words[i])) { 4: 30: in_word = false; -: 31: } -: 32: } 1: 33: return num_words; -: 34:} -: 35: -: 36: 20: 37:bool _is_letter(char ch) { 20: 38: if(ch > 'a' && ch < 'z') { 13: 39: return true; -: 40: } 7: 41: else if(ch > 'A' && ch < 'Z') { 1: 42: return true; -: 43: } -: 44: else { 6: 45: return false; -: 46: } -: 47:} -: 48: -: 49:#define COUNT_WORDS_C_VERSION 2 -: 50: -: 51:/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */