#include<iostream.h>
#include<fstream.h>
int main()
{
ifstream infile("text.txt");
char ch[50];
int count=0,i;
for(i=0;infile.eof()==0;i++)
{
infile.getline(ch,50);
if(ch[i]=='\n')
if(ch[i-1]=='.')
count++;
}
cout<<"Total number of lines are:"<<count;
}
I tried this code but it doesnt seem to work.I used the logic to take all the file contents in ch and then subsequently check for newline character and '.'
How do I make it work.
Please help?
EDIT new code
#include<iostream.h>
#include<fstream.h>
int main()
{
ifstream infile("text.txt");
char ch[50];
int count=0,i;
while(!infile.eof())
{
infile.getline(ch,50);
for(i=1;ch[i]!='\n';i++);
if(ch[i-1]=='.')
count++;
}
cout<<"Total number of lines are:"<<count;
}