Hi,
i am making a text editor with mouse programming.Given is my code .the compiler is not giving any error but i am unable to use enter,delete,backspace and arrow keys .
can any one please tell me the logic with which i can make my project more better.
THANKS in advance to all.

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
#include<string.h>
#include<dos.h>

graphic(void);

#define sett() settextstyle(2,0,4)
#define PATT printf("\n ************************************************************************** \n");
#define PATTERN printf("\n ************************************************************************** \n");
#define jk 10

//GLOBAL VARIABLES
char str[100];
int point=0;
int size=1;
int type=0;
static int mat1[jk][jk], mat2[jk][jk];
int const num1=7;
float myarray[num1][num1];


//FUNCTIONS
void first(void);
initmouse();
void showmouseptr();
void getmousepos(int *,int *,int *);

open();
save();
save_as();
new_file();
cut();
copy();
paste();
bold();
italic();
underline();
all_right();
all_left();
all_mid();
all_just();
highlight();
ssaver();

union REGS i,o;

void main(void)
{
ssaver();
first();
}


int left,right,top,bottom;


void first()
{
int gd=DETECT,gm,maxx,maxy,y1,y2,fst;
int left,right,top,bottom;
initgraph(&gd,&gm,"c:\\tc\\bgi");

if(initmouse()==0)
{
closegraph();
restorecrtmode();
printf("\nMouse driver not loaded");
exit(1);
}

left = getmaxx() -getmaxx()+1;
   top = getmaxy()-getmaxy()+1;
   right = getmaxx();
   bottom = getmaxy()-getmaxy()+20;
   setcolor(BLUE);
      /* draw a rectangle */
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"file name");

   setbkcolor(LIGHTGRAY);

   right=getmaxx()/7;
   top=bottom;
   bottom=bottom+20;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"select");

   left=right;
   right=(getmaxx()/5)*2;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"text_type");

   settextstyle(0,0,1);
   outtextxy(167,top+10,"A");
   rectangle(165,top,187,bottom);
   settextstyle(4,0,1);
   outtextxy(190,top,"A");
   rectangle(187,top,209,bottom);
   settextstyle(3,0,1);
   outtextxy(212,top,"A");
   rectangle(209,top,231,bottom);
   settextstyle(1,0,1);
   outtextxy(235,top,"A");
   rectangle(231,top,right,bottom);

   settextstyle(0,0,1);

   left=right;
   right=(getmaxx()/5)*3;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"t_size");

   rectangle(320,top,335,bottom);
   outtextxy(322,top+10,"s");
   rectangle(335,top,350,bottom);
   outtextxy(337,top+10,"n");
   rectangle(350,top,365,bottom);
   outtextxy(352,top+10,"l");
   rectangle(365,top,right,bottom);
   outtextxy(367,top+10,"vl");

   left=right;
   right=(getmaxx()/5)*4;
   rectangle(left,top,right,bottom);
   setcolor(RED);
   outtextxy(left+6,top+10,"A");
   setcolor(BLUE);

   setfillstyle(SOLID_FILL,BLUE);
   bar3d(400,top,418,bottom,0,0);
   setfillstyle(SOLID_FILL,9);
   bar3d(418,top,436,bottom,0,0);
   setfillstyle(SOLID_FILL,10);
   bar3d(436,top,454,bottom,0,0);
   setfillstyle(SOLID_FILL,4);
   bar3d(454,top,472,bottom,0,0);
   setfillstyle(SOLID_FILL,14);
   bar3d(472,top,490,bottom,0,0);
   setfillstyle(SOLID_FILL,15);
   bar3d(490,top,right,bottom,0,0);

   left=right;
   right=getmaxx();
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"bkc");

   setfillstyle(SOLID_FILL,0);
   bar3d(545,top,560,bottom,0,0);
   setfillstyle(SOLID_FILL,1);
   bar3d(560,top,575,bottom,0,0);
   setfillstyle(SOLID_FILL,2);
   bar3d(575,top,590,bottom,0,0);
   setfillstyle(SOLID_FILL,3);
   bar3d(590,top,605,bottom,0,0);
   setfillstyle(SOLID_FILL,4);
   bar3d(605,top,620,bottom,0,0);
   setfillstyle(SOLID_FILL,5);
   bar3d(620,top,right,bottom,0,0);

   left=1;
   right=getmaxx()/7;
   top=bottom;
   bottom=bottom+20;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"cut");

   left=right;
   right=(getmaxx()/7)*2;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"copy");

   left=right;
   right=(getmaxx()/7)*3;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"paste");

   left=right;
   right=(getmaxx()/7)*4;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"open ");

   left=right;
   right=(getmaxx()/7)*5;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"new ");

   left=right;
   right=(getmaxx()/7)*6;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"save ");

   left=right;
   right=getmaxx();
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"save as  ");

   left=1;
   right=(getmaxx()/8);
   top=bottom;
   bottom=bottom+20;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"bold");

   left=right;
   right=(getmaxx()/8)*2;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"italic");

   left=right;
   right=(getmaxx()/8)*3;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"underline");

   left=right;
   right=(getmaxx()/8)*4;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"right");

   left=right;
   right=(getmaxx()/8)*5;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"left");

   left=right;
   right=(getmaxx()/8)*6;
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"mid");

   left=right;
   right=getmaxx();
   rectangle(left,top,right,bottom);
   outtextxy(left+2,top+10,"highlight");

   setfillstyle(SOLID_FILL,6);
   bar3d(545,top,560,bottom,0,0);
   setfillstyle(SOLID_FILL,1);
   bar3d(560,top,575,bottom,0,0);
   setfillstyle(SOLID_FILL,2);
   bar3d(575,top,590,bottom,0,0);
   setfillstyle(SOLID_FILL,3);
   bar3d(590,top,605,bottom,0,0);
   setfillstyle(SOLID_FILL,4);
   bar3d(605,top,620,bottom,0,0);
   setfillstyle(SOLID_FILL,5);
   bar3d(620,top,right,bottom,0,0);

   rectangle(606,0,639,20);
   outtextxy(620,10,"X");

   left=1;
   right=getmaxx();
   top=bottom;
   bottom=getmaxy();


//restrictmouseptr(1,1,x,y);
showmouseptr();
int button,x1;

char t,temp[2]={"a"};
moveto(10,100);
while(1)

{
getmousepos(&button,&x1,&y1);
//textbackground(BLUE);
// setcolor(BLACK);

if(kbhit())
{
int y;
	if(getx()==(getmaxx()-10)||getx()>(getmaxx()-10))
	{
	int y=gety()+10;
	moveto(10,y);
	}
	t=getch();
	if(t=='\r')
	     {moveto(0,y+10);}
	temp[0]=t;
	outtext(temp);
	str[point]=t;
	point++;
}

if(x1>0 &&x1<639 &&y1>0 &&y1<20 && button==1){/*file name();*/}

if(x1>164 &&x1<186 &&y1>20 &&y1<40 && button==1){settextstyle(0,0,size);type=0;/*defultttype;*/}
if(x1>186 &&x1<209 &&y1>20 &&y1<40 && button==1){settextstyle(4,0,size);type=4;/*gothicttype;*/}
if(x1>209 &&x1<231 &&y1>20 &&y1<40 && button==1){settextstyle(3,0,size);type=3;/*senserrayttype;*/}
if(x1>231 &&x1<251 &&y1>20 &&y1<40 && button==1){settextstyle(1,0,size);type=1;/*triplexttype;*/}

if(x1>320 &&x1<335 &&y1>20 &&y1<40 && button==1){settextstyle(type,HORIZ_DIR,1);size=1;/*tsize;*/}
if(x1>335 &&x1<350 &&y1>20 &&y1<40 && button==1){settextstyle(type,HORIZ_DIR,2);size=2;/*tsize;*/}
if(x1>350 &&x1<365 &&y1>20 &&y1<40 && button==1){settextstyle(type,HORIZ_DIR,3);size=3;/*tsize;*/}
if(x1>365 &&x1<380 &&y1>20 &&y1<40 && button==1){settextstyle(type,HORIZ_DIR,4);size=4;/*tsize;*/}

if(x1>400 &&x1<416 &&y1>20 &&y1<40 && button==1){setcolor(BLUE);/*tcolor;*/}
if(x1>416 &&x1<437 &&y1>20 &&y1<40 && button==1){setcolor(LIGHTBLUE);/*tcolor;*/}
if(x1>437 &&x1<453 &&y1>20 &&y1<40 && button==1){setcolor(LIGHTGREEN);/*tcolor;*/}
if(x1>453 &&x1<472 &&y1>20 &&y1<40 && button==1){setcolor(RED);/*tcolor;*/}
if(x1>472 &&x1<490 &&y1>20 &&y1<40 && button==1){setcolor(YELLOW);/*tcolor;*/}
if(x1>490 &&x1<507 &&y1>20 &&y1<40 && button==1){setcolor(WHITE);/*tcolor;*/}

if(x1>544 &&x1<560 &&y1>20 &&y1<40 && button==1){setbkcolor(0);/*bkcolor;*/}
if(x1>544 &&x1<574 &&y1>20 &&y1<40 && button==1){setbkcolor(1);/*bkcolor;*/}
if(x1>574 &&x1<590 &&y1>20 &&y1<40 && button==1){setbkcolor(2);/*bkcolor;*/}
if(x1>590 &&x1<603 &&y1>20 &&y1<40 && button==1){setbkcolor(3);/*bkcolor;*/}
if(x1>603 &&x1<621 &&y1>20 &&y1<40 && button==1){setbkcolor(4);/*bkcolor;*/}
if(x1>621 &&x1<639 &&y1>20 &&y1<40 && button==1){setbkcolor(5);/*bkcolor;*/}

if(x1>0   &&x1<90  &&y1>40 &&y1<60 && button==1){/*cut;*/}
if(x1>90  &&x1<180 &&y1>40 &&y1<60 && button==1){/*copy;*/}
if(x1>180 &&x1<273 &&y1>40 &&y1<60 && button==1){/*paste;*/}
if(x1>273 &&x1<365 &&y1>40 &&y1<60 && button==1){open();}
if(x1>365 &&x1<455 &&y1>40 &&y1<60 && button==1){new_file();}
if(x1>455 &&x1<546 &&y1>40 &&y1<60 && button==1){save();}
if(x1>546 &&x1<635 &&y1>40 &&y1<60 && button==1){save_as();}

if(x1>0   &&x1<75  &&y1>60 &&y1<80 && button==1){/*bold();*/}
if(x1>75  &&x1<158 &&y1>60 &&y1<80 && button==1){/*italic();*/}
if(x1>158 &&x1<236 &&y1>60 &&y1<80 && button==1){/*underline();*/}
if(x1>236 &&x1<316 &&y1>60 &&y1<80 && button==1){/*right();*/}
if(x1>316 &&x1<394 &&y1>60 &&y1<80 && button==1){/*left();*/}
if(x1>394 &&x1<474 &&y1>60 &&y1<80 && button==1){/*mid();*/}

if(x1>544 &&x1<560 &&y1>60 &&y1<80 && button==1){textbackground(6);/*highlighter;*/}
if(x1>544 &&x1<574 &&y1>60 &&y1<80 && button==1){textbackground(1);/*highlighter;*/}
if(x1>574 &&x1<590 &&y1>60 &&y1<80 && button==1){textbackground(2);/*highlighter;*/}
if(x1>590 &&x1<603 &&y1>60 &&y1<80 && button==1){textbackground(3);/*highlighter;*/}
if(x1>603 &&x1<621 &&y1>60 &&y1<80 && button==1){textbackground(4);/*highlighter;*/}
if(x1>621 &&x1<639 &&y1>60 &&y1<80 && button==1){textbackground(5);/*highlighter;*/}

if(x1>600 &&x1<639 &&y1>0 &&y1<20 && button==1)
	{
	closegraph();
	restorecrtmode();
	exit(1);
	}

}
}


initmouse()
 {
 i.x.ax=0;
 int86(0x33,&i,&o);
 return(o.x.ax);
 }

void showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}


void getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}

//to open a file
open()
{
char ch;
char name[20];
cleardevice();
closegraph();
printf("enter file name or address");
gets(name);
FILE *fptr;
first();
fptr=fopen(name,"r");
int n=0;
while((ch=getc(fptr))!=EOF)
 {
   str[n]=ch;
   n++;
 }
 setcolor(BLUE);
 moveto(10,100);
 outtext("abc");
 outtext(str);

fclose(fptr);
return(0);
}

//to save a file in test.txt
save()
{
FILE *fptr;
char ch;
fptr=fopen("test.txt","w");
for(int n=0;n<strlen(str);n++)
{
   ch=str[n];
   fprintf(fptr,"%c",ch);
}
fclose(fptr);
return(0);
}

//save as functon
save_as()
{
char ch;
char name[20];

cleardevice();
closegraph();
printf("enter file name or address");
gets(name);
FILE *fptr;
fptr=fopen(name,"w");
for(int n=0;n<strlen(str);n++)
{
   ch=str[n];
   fprintf(fptr,"%c",ch);
}
fclose(fptr);
first();
moveto(10,100);
outtext(str);
return(0);
}

//opens a new file on window
new_file()
{
clrscr();
cleardevice();
first();
return(0);
}


//loadinggggg
ssaver()
{
    /* request auto detection*/
    int gdriver = DETECT, gmode, errorcode;
    int maxx, maxy,midx,midy,left,right,top,bottom;

    /* initialize graphics, local variables*/

    initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

    /* read result of initialization   */
    errorcode = graphresult();

    if (errorcode != grOk)
    /* an error occurred  */
    {
       printf("Graphics error: %s\n", grapherrormsg(errorcode));
       printf("Press any key to halt:");
       getch();
       exit(1);
       /* terminate with an error code    */
    }

    setcolor(RED);
    rectangle(5,5,getmaxx()-5,getmaxy()-5);

    setcolor(8);
    setbkcolor(15);
    settextstyle(DEFAULT_FONT,HORIZ_DIR,4);
    moveto(45,40);
    outtext("THE TEXT EDITOR");
    moveto(175,420);
    outtext("LOADING");
    left=getmaxx()/2;
    top=getmaxy()/2;
    right=getmaxx()/2;
    bottom=getmaxy()/2;
    rectangle(left,top,right,bottom);
    delay(500);
    //cleardevice();
  int n=1;
  while(right<getmaxx()-20&&bottom<getmaxy()-10)
  { if(n!=15)
    {
    setcolor(n);
    left=left-20;
    top=top-10;
    right=right+20;
    bottom=bottom+10;
    rectangle(left,top,right,bottom);
    delay(500);
    //cleardevice();
    }
    n++;
  }

  return(0);

}

Standard C cannot do what you want. Input is only accepted using the ENTER key. You have to go into non-standard specialized code that most compilers do not contain.

Standard C cannot do what you want. Input is only accepted using the ENTER key. You have to go into non-standard specialized code that most compilers do not contain.

i was using a logic that if a user enter a right arrow key then moveto(x+5,y)
is that right??:-/

You have to go into non-standard specialized code that most compilers do not contain.

You say that as if the code isn't already completely non-standard and clearly based on libraries supported by Turbo C. Just say "use getch()" and be done with it, since this is a time when getch() is warranted. :icon_rolleyes:

You say that as if the code isn't already completely non-standard and clearly based on libraries supported by Turbo C. Just say "use getch()" and be done with it, since this is a time when getch() is warranted. :icon_rolleyes:

can you please explain more clearly!!!!!!!
thanks to all for your attention

can you please explain more clearly!!!!!!!

I'll spell it out for you: G. O. O. G. L. E

I'll spell it out for you: G. O. O. G. L. E

look i am using getch to input and all other chars are working but enter and delete keys are not working.

look i am using getch to input and all other chars are working but enter and delete keys are not working.

This doesn't change my answer.

You say that as if the code isn't already completely non-standard and clearly based on libraries supported by Turbo C. Just say "use getch()" and be done with it, since this is a time when getch() is warranted. :icon_rolleyes:

Didn't look at the code closely enough (if at all).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.