in c++
Expert Answer
- Comment
NOTE:- IN CASE OF ANY QUERY FEEL FREE TO ASK IN COMMENT ANYTIME.........HAPPY LEARNING AND KEEP CHEGGING.....
code
#include<iostream> #include<fstream> using namespace std; int main() { ifstream fin("word.txt"); //opening a file int line=1,word=0; //assign values to line and word char ch; int character=0,space=0; //character and space set to 0 fin.seekg(0,ios::beg); //move to begining of file while(fin) { fin.get(ch); //get every character if(ch==' '||ch=='\n') //new line or space encounterd word++; if(ch=='\n') //new line line++; if(!(ch==' '|| ch=='\n')) //not space or not a new line then its a character character++; if(ch== ' ') //space space++; } //display result cout<<"Number of characters without spaces:\t"<<character-1; cout<<"\nNumber of characters with spaces:\t"<<character+space-2; cout<<"\nNumber of words:\t\t\t"<<word; cout<<"\nNumber of lines:\t\t\t"<<line; cout<<"\nSpaces count:\t\t\t\t"<<space-1; fin.close(); //closing file return 0; }
code image
output
--------------I hope my answer met all your requirements......Thank You-----------
ليست هناك تعليقات:
إرسال تعليق