C++ Practical
File Handling Snippet-6
Question : Write a program in C++ to count number of uppercase alphabets present in a text file "ARTICLE.TXT"
Answer:
// Write a program in C++ to count number of uppercase alphabets // present in a text file "ARTICLE.TXT" #include <iostream.h> #include <fstream.h> #include <process.h> #include <ctype.h> int main() { ifstream fin("ARTICLE.TXT", ios::in); if (!fin) { cout << "Error opening file ARTICLE.TXT\n Exiting..." << endl; exit(1); } char ch; int count=0; while(!fin.eof()) { fin.get(ch); if(isalpha(ch)) { if (ch >= 'A' && ch <= 'Z') count++; } } cout<<"Number of UPPERCASE alphabets in file are " << count << endl; fin.close(); return 0; }
Screen Output:
No comments:
Post a Comment
We love to hear your thoughts about this post!
Note: only a member of this blog may post a comment.