#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void countline();
void main()
{ clrscr();
int ch;
cout<<"\n 1. wants to show the reversed file";
cout<<"\n 2. wants to know the number of lines";
cout<<"\n enter the choice ";
cin>>ch;
switch(ch)
{case 1 :
char str[100];
fstream f1("mydata.txt",ios::in);
if (!f1)
{ cout<<"\n could not find";
getch();
exit(-1);
}
char ch;
cout<<"\n THE SENTENCE IS : ";
while (!f1.eof())
{ f1.get(ch);
cout<<ch;
}
f1.close();
char c;
int i=0;
fstream f("mydata.txt",ios::in);
while (!f.eof())
{ f.get(c);
str[i]=c;
i++;
}
str[i]='\0';
cout<<"\n THE REVERSED SENTENCE IS :";
for ( i=0; str[i]!='\0'; i++);
for (int j=i-1; j>=0; j--)
cout<<str[j];
break;
case 2:
countline();
break;
}
getch();
}
void countline()
{ char c;
fstream f1("mydata.txt",ios::in);
if (!f1)
{ cout<<"\n could not find";
getch();
exit(-1);
}
char ch;
cout<<"\n THE SENTENCE IS : ";
while (!f1.eof())
{ f1.get(ch);
cout<<ch;
}
f1.close();
fstream f("mydata.txt",ios::in);
int i=0;
while (!f.eof())
{ f.get(c);
if (c=='.' || c=='!' || c=='?')
i++;
}
f.close();
cout<<"\n number of line are : "<<i;
return;
}
0 comments:
Post a Comment