IMPLEMENTATION OF A SIMPLE TEXT EDITOR

Aim
To Implement simplet Text Editor using c programin CS1207 SYSTEM SOFTWARE LAB
Source code in c Program for 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;

void cur_pos()
{
curx=wherex();
cury=wherey();
textcolor(12);
textbackground(9);
gotoxy(35,1);
cout<<"\n";
cout<<"##############################################\n";
cout<<"\n";
cout<<"\t\tTEXT EDITOR\n";
cout<<"##############################################\n";
cout<<"\n Type your text and then press ESC key\n";
gotoxy(100,500);
cprintf("%2d%2d",cury,curx);
gotoxy(curx,cury);
}

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: //down arrow
gotoxy(curx,cury+1);
break;
case 77: //right side
gotoxy(curx+1,cury);
break;
case 72: //up arrow
gotoxy(curx,cury-1);
break;
case 75: //left side
gotoxy(curx-1,cury);
break;
case 32: //space
printf(" ");
buff[count++]=' ';
break;
case 13: //new line
gotoxy(1,cury+1);
buff[count++]='\n';
break;
default:
textcolor(13);
if((c>=65 && c<=122) (c>48 && c<57))
cprintf("%c",c);
break;
}
buff[count++]=c;
cur_pos();
}
cprintf("\n\nDo you want to save? (y/n)");
scanf("%c",&c);
if((c=='y')(c=='Y'))
{
cprintf("\n\nEnter the file name with extension in 8 characters only");
scanf("%s",filename);
outfile.open(filename,ios::out);
outfile<<buff;
outfile.close();
cout<<"\nDo you want to open? (y/n) \n";
ch=getch();
if((ch=='y')(ch=='Y'))
{
cprintf("\n\nEnter the file name to open");
scanf("%s",filename);
infile.open(filename,ios::in);
infile.get(buff,count,'*');
gotoxy(90,1);
printf("%s",buff);
getch();
infile.close();
}
}
}

Post a Comment

0 Comments