TheFestFever.com

Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 22: Write a C++ program to count no of word “to” in a file.

#include<fstream>
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
	int count;
	fstream f;
	f.open("C:\\Users\\Sandeep\\Desktop\\file1.txt",ios::in|ios::out|ios::binary);
	char ch[50];

	if(!f)
		cout<<"\nfile doest exist!!!";
	else
		while(f)
		{
			f>>ch;
			if(strcmp(ch,”to”)==0)
			count++;
		}
		cout<<"\nno of to in the paragraph : "<<count;
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.