Friday, 22 March 2019

CPP-EX33

count the no. of words in a file

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>

void main()
{
fstream file;
clrscr();

file.open("c:\tc\bin\archana3.txt",ios::in|ios::out);
char ch;
int i,count=0;

file.seekg(0);
file>>ch;

while(! file.eof())
{
file.get(ch);
if(ch == ' ')
count++;
}
cout<<"\n No. of word:-"<<count;
file.close();

getch();
}