Program:-
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int
coc=0,cow=0,col=0;
ifstream
f1;
char
ch;
f1.open("newfile.txt");
while(!f1.eof())
{
f1.get(ch);
cout<<ch;
coc++;
if(ch==' ' || ch=='\n')
{
cow++;
}
if(ch=='\n')
{
col++;
}
}
cout<<"\n
Count of characters: "<<coc-2;
cout<<"\n
Count of Words: "<<cow-1;
cout<<"\n
Count of Lines: "<<col-1;
}
The file contains:
Hi
How are you doing
Good
Output:-
[root@SAR118
Desktop]# gcc prog1.cpp
[root@SAR118 Desktop]# ./a.out
[root@SAR118 Desktop]#
Count of characters: 23
Count of Words: 6
Count of Lines: 3
No comments:
Post a Comment