#include #include #include #define SIZE_LINE 1000+1 using namespace std; bool isAllUpper(const char * str); int countUpperWord(const char * str); int main(void) { FILE * file = fopen("parole.txt", "rt"); if (file != NULL) { char str[SIZE_LINE]; int countWord = 0; while (fgets(str, sizeof(str), file)) { countWord = countWord + countUpperWord(str); } cout << "Total all-uppercase words: " << countWord << endl; fclose(file); } else { perror("Error (source)"); } return 0; } bool isAllUpper(const char * str) { int countAplha = 0; if (strlen(str) == 0) { return false; } for (int i = 0; str[i] != '\0'; i++) { if (isalpha(str[i])) { countAplha++; if (!isupper(str[i])) { return false; } } } return true; } int countUpperWord(const char * str) { char buffer[SIZE_LINE]; int countWord = 0; strcpy(buffer, str); for (char * pc = buffer; (pc = strtok(pc, " \n")) != NULL; pc = NULL) { if (isAllUpper(pc)) { countWord++; } } return countWord; }