Thursday, 4 May 2017

AIM: Write a C++ program that counts number of words in a file.


CODING:
#include<fstream.h>
#include<conio.h>
main()
{
clrscr();
int count=1;
ifstream f1;
f1.open("student.txt");
f1.seekg(0);
char ch;
while(! f1.eof())
{
 f1.get(ch);
 }
 if(ch==' '|| ch=='\t'|| ch=='\n')
 {
  count++;
 }
 cout<<"Number of words="<<count;
 f1.close();
 getch();
 return 0;

}

No comments:

Post a Comment

About Me

Hi, I am Prof. Amol Zade, working in the field of teaching and research from last more than 10 years. My area of interests are Artificial Intelligence, Wireless Networking, Algorithms. I have 16 International paper publications along with 4 International Conference; also 3 Books published. published on Object Oriented Programming with open source approach.