Text or Screen Editor in C++ Language
Write a program in C++ Language to implement a Text or Screen Editor which can edit the entered text on screen.Program should make a file which will be used for storing text .
Text or Screen Editor in C++ Language Code
#include #include #include #define left 21 #define top 7 #define right 59 #define bottom 24 void main() { clrscr(); window(left,top-1,right,bottom); char buff[100][40]; FILE *fp; fp=fopen("editfile.txt","w"); clrscr(); cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r"); int x=wherex(); int y=wherey(); //gotoxy(x,y); char ch; int row; int col; int i; do { flushall(); ch=getch(); int i=0,j=0; if(ch==0) { ch=getch(); } //int char c; switch(ch) { case '='://open fp=fopen("editfile.txt","r"); i=0; clrscr(); while(i<15) { c=fgetc(fp); if(c=='\n') { i++; } cprintf("%c",c); } getch(); case '<': //save i=1; fp=fopen("editfile.txt","w"); while(i<16) { j=1; while( buff[i][j]!='~' && buff[i][j]!='\r') { fputc(buff[i][j],fp); j++; } fputc('\n',fp); i++; } fputc('\0',fp); getch(); clrscr(); gotoxy(x,y); cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r"); break; case ';': //NEW FILE //cprintf("yo"); clrscr(); cprintf("F1 New F2 SAVE F3 OPEN F4 EXIT\n\r"); cprintf("NEW FILE CREATED\n\r"); row=1; col=0; i=0; while(i<15) { strcpy(buff[i],NULL); buff[i][0]='~'; buff[i][1]='~'; buff[i][2]=NULL; i++; } break; case '>'://exit t break; case '\r':// return character next line row++; col=0; gotoxy(x+col,y+row); break; case 'P': row++; gotoxy(x+col,y+row); break; case 'H': if(row!=1) { row--; gotoxy(x+col,y+row); } break; case 'M': col++; if(col==39) { col=0; row++; } gotoxy(x+col,y+row); break; case 'K': col--; if(col==-1) { col=0; } gotoxy(x+col,y+row); break; case '\b': if((col-1)==-1) { break; } if(buff[row][col+1]=='~') { buff[row][col]='~'; buff[row][col+1]=NULL; gotoxy(x+col-1,y+row); cprintf(" "); gotoxy(x+col-1,y+row); col--; } else { i=strlen(buff[row]); j=col; gotoxy(x+col-1,y+row); while(j<=i) { buff[row][j]=buff[row][j+1]; if(buff[row][j+1]=='~') break; cprintf("%c",buff[row][j+1]); j++; } cprintf(" "); buff[row][i-1]=NULL; gotoxy(x+col-1,y+row); col--; } break; case 'S': if(buff[row][col+1]=='~') { buff[row][col]='~'; buff[row][col+1]=NULL; gotoxy(x+col-1,y+row); cprintf(" "); gotoxy(x+col,y+row); } else { i=strlen(buff[row]); j=col+1; gotoxy(x+col,y+row); while(j<=i) { buff[row][j]=buff[row][j+1]; if(buff[row][j+1]=='~') break; cprintf("%c",buff[row][j+1]); j++; } cprintf(" "); buff[row][i-1]=NULL; gotoxy(x+col,y+row); } break; default: //row=where col++; if(col==39) { row++; col=0; gotoxy(x+col,y+row); } i=strlen(buff[row]); if( (strlen(buff[row])-1) { for(i=strlen(buff[row])-1;i<col;++i) <br=""> { buff[row][i]=' '; } } // else // col++; buff[row][col+1]='~'; buff[row][col]=ch; buff[row][col+2]=NULL; cprintf("%c",ch); } }while(ch!='>'); }
Leave a Reply