xxx

// cctypes.cpp -- using the ctype.h library #include <iostream> #include <cctype> // prototypes for character functions int main() { using namespace std; cout << "Enter text for analysis, and type @" " to terminate input.\n"; char ch; int whitespace = 0; int digits = 0; int chars = 0; int punct = 0; int others = 0; cin.get(ch); // get first character while (ch != '@') // test for sentinel { if(isalpha(ch)) // is it an alphabetic character? chars++; else if(isspace(ch)) // is it a whitespace character? whitespace++; else if(isdigit(ch)) // is it a digit? digits++; else if(ispunct(ch)) // is it punctuation? punct++; else others++; cin.get(ch); // get next character } cout << chars << " letters, " << whitespace << " whitespace, " << digits << " digits, " << punct << " punctuations, " << others << " others.\n"; // cin.get(); // cin.get(); return 0; }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章