1 A) Texteditor

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Text Editor

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<dos.h>
#include<iostream.h>
#include<fstream.h>

char filename[15];
char buff[1000];
int curx,cury,count=0;

void cur_pos()
{
curx=wherex();
cury=wherey();
textcolor(10);
textbackground(9);
gotoxy(35,1);
cout<<"\n"<<"TEXT EDITOR";
cout<<"\n\n";
cout<<"Type Ur Text &press escape key\n";
gotoxy(100,100);
}

void main()
{
char ch,c;
ofstream outfile;
ifstream infile;
clrscr();
cur_pos();
curx=wherex();
cury=wherey();
while(c!=27)
{
c=getch();
switch(c)
{
case 80:
gotoxy(curx,cury+1);
break;
case 77:
gotoxy(curx+1,cury);
break;
case 72:
gotoxy(curx,cury-1);
break;
case 75:
gotoxy(curx-1,cury);
break;
case 32:
printf(" ");
break;
case 13:
gotoxy(1,cury+1);
buff[count++]='\n';
break;
default:
textcolor(13);
if((c>=65&&c<=122)||(c>=48&&c<=57))
cprintf("%c",c);
}
buff[count++]=c;
cur_pos();
}
cprintf("\n\nDo U want to save? (y/n)");
scanf("%c",&c);
if((c=='y')||(c=='Y'))
{
cprintf("\n\nEnter the filename with extension in 8 characters only");
scanf("%s",filename);
outfile.open(filename,ios::out);
outfile<<buff;
outfile.close();
cout<<"\nDo U want to open(y/n)\n";
ch=getch();
if((ch=='y')||(ch=='Y'))
{
cprintf("\n\nEnter the filename to open");
scanf("%s",filename);
infile.open(filename,ios::in);
infile.get(buff,count,'*');
gotoxy(90,1);
printf("%s",buff);
getch();
infile.close();
}
}
}

You might also like