Skip to main content

Featured

functions in Python

File handling program to count lines where a line starts with letter A

/*This program counts the lines where a statement begins with letter A from a file*/

#include<fstream.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
fstream f;
f.open("story.txt",ios::out);
f<<"This is a sample test for lines count \n";
f<<"And This program tells how many lines in a file\n";
f<<"Where A line starts with letter A\n";
f<<"Also this program is good example for file handling programs\n";

f.close();
char ch;
int lines=0;
f.open("story.txt",ios::in);
f.get(ch);
while(!f.eof())
{
if(ch=='\n')
{
f.get(ch);
if(ch=='A')lines++;
}
f.get(ch);
}
cout<<"count of lines->"<<lines<<endl;
f.close();
getch();
}

Comments

Popular Posts