Wednesday 15 February 2012

C++ program in file handling for counting lines in a file starting with 'A'

C++ program in file handling for counting lines in a file starting with 'A'

#include <fstream.h>
#include <conio.h>
#include <ctype.h>
void countLine()
{
char Aline[80];
int Count  = 0;
ifstream File("LINES.TXT");
while (File.getline(Aline, 80, '\n'))
if (Aline[0] == 'A')
Count++;
File.close();
cout << "No. of lines started with A : " << Count << endl;
}
void main( )
{
clrscr();
countLine();
}

step by step explanation:

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

No comments:

Post a Comment