Write a function in C++ to count the number of line started with alphabet ‘A’ or ‘T’ in a text file “NOTES.TXT”.

void CountLine( )
{
char line[80];
int Count=0;
ifstream fin (“NOTES.TXT”);
while(!fin.eof())
{
fin.getline(line,80,‘\n’))
if (line[0]== ‘A’||line[0]==’T’)
Count++;
}

cout<<"There are "<<Count<<" Lines in file to start with a letter T or t."<<endl;
fin.close( );
}

void main()
{
  CountLine();
}




No comments

Post your comments

Powered by Blogger.