#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
ifstream fin;
int count=0,num,l=1;
char name[20],line[20],ch;
clrscr();
system("dir/w *.txt");
cout<<"Enter File Name :";
cin.getline(name,20);
clrscr();
fin.open(name,ios::in);
fin.get(ch);
while(!fin.eof())
{
if(ch=='\n')
l++; //Line Counter
cout<<ch;
fin.get(ch);
}
fin.close();
cout<<"\n\nReading Completed..."<<endl;
cout<<"There are "<<l<<" Lines in File";
cout<<endl<<endl;
fin.open(name,ios::in);
cout<<"Which Line You Want to Print From "<<name<<" File :";
cin>>num;
if(num<=l)
{
while(!fin.eof())
{
fin.getline(line,80,'\n');
count++;
if(count==num)
{
cout<<endl<<line<<endl;
}
}
fin.close();
}
else
cout<<"Line Not Found...";
getch();
}
#include<conio.h>
#include<stdlib.h>
void main()
{
ifstream fin;
int count=0,num,l=1;
char name[20],line[20],ch;
clrscr();
system("dir/w *.txt");
cout<<"Enter File Name :";
cin.getline(name,20);
clrscr();
fin.open(name,ios::in);
fin.get(ch);
while(!fin.eof())
{
if(ch=='\n')
l++; //Line Counter
cout<<ch;
fin.get(ch);
}
fin.close();
cout<<"\n\nReading Completed..."<<endl;
cout<<"There are "<<l<<" Lines in File";
cout<<endl<<endl;
fin.open(name,ios::in);
cout<<"Which Line You Want to Print From "<<name<<" File :";
cin>>num;
if(num<=l)
{
while(!fin.eof())
{
fin.getline(line,80,'\n');
count++;
if(count==num)
{
cout<<endl<<line<<endl;
}
}
fin.close();
}
else
cout<<"Line Not Found...";
getch();
}