Featured
- Get link
- X
- Other Apps
File handling Program to count words in C++
#include<fstream.h>
#include<string.h>
#include<conio.h>
void main()
{
fstream f;
f.open("story.txt",ios::out);
f<<"This is a story of a boy. This is also a moral story. Is this a good story? Yes, this is a good story";
f.close();
char ch[10];
int count=0;
f.open("story.txt",ios::in);
f>>ch;
while(!f.eof())
{
if(strcmp(ch,"this")==0||strcmp(ch,"This")==0)
count++;
f>>ch;
}
cout<<count;
f.close();
getch();
}
//The above program gives output 4
#include<string.h>
#include<conio.h>
void main()
{
fstream f;
f.open("story.txt",ios::out);
f<<"This is a story of a boy. This is also a moral story. Is this a good story? Yes, this is a good story";
f.close();
char ch[10];
int count=0;
f.open("story.txt",ios::in);
f>>ch;
while(!f.eof())
{
if(strcmp(ch,"this")==0||strcmp(ch,"This")==0)
count++;
f>>ch;
}
cout<<count;
f.close();
getch();
}
//The above program gives output 4
- Get link
- X
- Other Apps
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment