Featured
- Get link
- X
- Other Apps
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();
}
#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();
}
- Get link
- X
- Other Apps
Labels:
C++ program to count lines
File handling program to count lines where a line starts with letter A
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment