Write a function in C++ to count number of lines from NOTES.TXT file. (a line can have maximum 80 characters or ends at ‘.’)

void countLines()

ifstream fin(“NOTES.TXT”);
char ch[80];
int count=0;
if (!fin)
{
cout<<”Error opening file!” ;
exit(0);
}
while(1)
{
fin.getline(ch,70,‘.’);
if (fin.eof())
break;
count++;
}
fin.close();
cout<<"There are "<<count<<" Lines in NOTES.TXT file.";
}

void main()
{
countLines();
}




No comments

Post your comments

Powered by Blogger.