Thursday 7 May 2015

COUNT NUMBER OF "LINES" PRESENT IN TEXT FILE

//Assume 60 characters in one line
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
void main()
{ ifstream fin;
char filename[12];
cout<<"himanshu singh-  enter file name\n ";
cin.getline(filename,12);
 fin.open(filename,ios::in);
 if(!fin)
 {cout<<"\n file not found ";
 exit(-1);
 }


char s[60];
int cnt=0;
while(!fin.eof())
{ fin.getline(s,60);
cnt++ ;
}
cout<<"HIMANSHU SINGH\n";
cout<<"total number of lines in file is">>cnt;
fin.close();
getch();
}                                                      FILE TO BE CHECK- LINE.TXT

OUTPUT 


No comments:

Post a Comment