10.
Text Editor
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
char fn[10],c;
class texteditor
{
public:
void create();
void append();
void view();
void del();
};
void main()
{
int choice;
while(1)
{
clrscr();
texteditor obj;
cout<<"\[Link]\[Link]\[Link]\[Link]\[Link]\
nENTER YOUR CHOICE:";
cin>>choice;
switch(choice)
{
case 1:
[Link]();
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
[Link]();
break;
case 5:
exit(0);
break;
default:
exit(0);
}
}
}
//Creation of file
void texteditor::create()
{
cout<<"\nENTER THE FILE NAME:";
cin>>fn;
ofstream fp1;
[Link](fn);
cout<<"\nENTER THE CONTENTS OF THE FILE:";
cout<<"\nSAVE AND EXIT: CTRL &S\n";
while(1)
{
c=getch();
if(c==32)
{
cout<<' ';
fp1<<c;
}
else if(c==13)
{
cout<<"\n";
fp1<<"\n";
}
else if(c==19)
{
cout<<"\nFILE SAVED AND CLOSED\n";
[Link]();
getch();
break;
}
else
{
cout<<c;
fp1<<c;
}
}
}
//Procedure for viewing the content of file
void texteditor::view()
{
char str[30];
cout<<"\nENTER THE FILE NAME:";
cin>>fn;
ifstream fp1(fn);
while(![Link]())
{
[Link](str,30);
cout<<str<<"\n";
}
[Link]();
getch();
}
//Procedure for appending data to a file
void texteditor::append()
{
cout<<"\nSAVE:CTRL &S";
cout<<"\nENTER THE FILE NAME:";
cin>>fn;
ofstream fp1(fn,ios::ate);
while(1)
{
c=getch();
if(c==13)
{
c='\n';
cout<<"\n";
fp1<<c;
}
else if(c==19)
{
break;
}
else
{
cout<<c;
fp1<<c;
}
}
[Link]();
}
//Procedure for deleting a file
void texteditor::del()
{
cout<<"\nENTER THE FILE NAME:";
cin>>fn;
remove(fn);
cout<<"\nFILE DELETED SUCCESSFULLY\n";
getch();
}