Wednesday 15 February 2012

Function to count and display the number of blank spaces present in a text file

Function to count and display the number of blank spaces present in a text file

#include <fstream.h>
#include <iostream.h>
#include <ctype.h>
#include <conio.h>
void display()
{
ifstream afile;
/* If NOTES.txt contains the following line :
C++ File handing in Class-12 */
afile.open("NOTES.TXT");
char ch;
int c = 0;
while(afile)
{
afile.get(ch);
if (ch == ' ' )
c++;
}
cout << "The number of blank spaces : " << c;
}
void main()
{
clrscr();
display();
}

step by step explanation:

1.the header file "iostream.h" is used to include the function cin and cout.
2.the header file"conio.h"is used to include the function like getch and clrscr.
3.void display is also a void type function .
4.void main is also a void type function it is worked under the curley brackets.

No comments:

Post a Comment