WAP a program to count the number of words present in a text file named“PARA.TXT”. Assume that each word is separated by a single blank/space character and no blanks/spaces in the beginning and end of the file.
#include<iostream.h>
#include<conio.h>
void main()
{
int total;
total=WordsCount( );
Cout<<"Total number of words are:"<<total;
getch();
}
int WordsCount( )
{ clrscr( );
ifstream fin("PARA.TXT",ios::in);
char ch;
int Words=1;
if(!fin)
{ cout<<”No words at all in the file”;
exit(0);
}
while(fin)
{fin.get(ch);
if(ch= =’ ‘)
Words++;
}
return words;
}
#include<iostream.h>
#include<conio.h>
void main()
{
int total;
total=WordsCount( );
Cout<<"Total number of words are:"<<total;
getch();
}
int WordsCount( )
{ clrscr( );
ifstream fin("PARA.TXT",ios::in);
char ch;
int Words=1;
if(!fin)
{ cout<<”No words at all in the file”;
exit(0);
}
while(fin)
{fin.get(ch);
if(ch= =’ ‘)
Words++;
}
return words;
}
No comments:
Post a Comment