Please Please Please Help me, gotoxy() along with the weird working of backspace is driving me crazy ... the comments are given with the stepts where I am falling ...

BTW ... this is the code for a notepad ...

Code:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <fcntl.h>
#include <stdlib.h>


int 	x,y;
//**************************************************************************
//                             Constants Block
//**************************************************************************
enum xKEYS {
		L_ARROW = 75 ,
		R_ARROW = 77 ,
		U_ARROW = 72 ,
		D_ARROW = 80 ,
		ALT_O   = 24 ,
		ALT_N   = 49 ,
		ALT_S   = 31 ,
		ALT_Q   = 16 ,
		ALT_H   = 34 ,
		ALT_C   = 47 ,
		F4      = 62 ,
		};

enum SCREENSTATS{
			MAXX = 80      ,
			MAXY = 24      ,
			AREAX = MAXX-1 ,
			AREAY = MAXY-1 ,
			MIDX = MAXX/2  ,
			MIDY = MAXY/2  ,
		};


//************************************************************************
//                         End of Constant Block
//************************************************************************



//************************************************************************
//                         Function ProtoTypes
//************************************************************************

int open_file();
int create_new_file();
int _Row(int limit,char msgs[],int pos1,char msgs2[],int pos2,char msgs3[],int pos3);


//************************************************************************
//                     End of Function ProtoType Block
//************************************************************************



//************************************************************************
//		           main() Program
//************************************************************************
int main()
{

	//*****************************/
	//         VARAIABLE block
	//*****************************/
	int		key;
	int		c;
	char*	msgs[] = {
				 "Alt + N (NewFile)"
				,"Alt + O (Open)"
				,"Alt + S (Save)"
				,"Alt + H (Help)"
				,"Alt + C (Close)"
				,"Alt + Q (Quit)"
				,"\nDo you want to save the Document"
				,"\nDo you wish to contiue "
				,"\n Y for Yes and N for No"

			 };

	int keysize;

	keysize=(sizeof msgs) / (sizeof msgs[0]);
	x=y=0;

	clrscr();

	textmode(3);

	 gotoxy(0,0);
	 _Row(40,msgs[0],4,msgs[1],15,msgs[2],24);

	 gotoxy(MAXX,MAXY);
	 _Row(40,msgs[3],4,msgs[4],15,msgs[5],24);

	textcolor(LIGHTGREEN);
	textbackground(BLACK);
	x=0,y=1;
  gotoxy(x,y);    // Here's problem-1: the cursor isnt returning as it supposed to the pointed location
  while( (key=getch()) != 27 )
	if( key == 0 )
		switch(getch())  // Incomplete Part ... Skip This whole Block
		{
			case L_ARROW:
				   //if(x>0)
				gotoxy(--x,y);
				break;
			case R_ARROW:
				//if(x<MAXX)
				gotoxy(++x,y);
				break;
			case U_ARROW:
				//if(y>0)
				gotoxy(x,--y);
				break;
			case D_ARROW:
				gotoxy(x,++y);
				break;
			case ALT_S:
				printf(msgs[6]);
				break;
			case F4:
				exit(0);

	}
	else
	{
	 if(key == 0x0a || key == 0x0d)
		cputs("\n");
	 if(key == 0x08)  // Backspace --- BIGGEST PROBLEM FOR ME, NOT SOLVED YET
	 {
		gotoxy(--(x=wherex()),(y=wherey()));
		key = 0;
	 }
	  cprintf("%c",key);
	  x=wherex();
	  y=wherey();
	 }

  return EXIT_SUCCESS;
}

//************************************************************************
//			   Function Definations
//************************************************************************

int newfile(char* fname,int key)
{
   FILE* in;
	  if ((in = fopen(fname, "w+")) == NULL)
	  {
		fprintf(stderr, "Cannot create new file.\n");
		return 1;
	  }

}

int _Row(int limit,char msgs[],int pos1,char msgs2[],int pos2,char msgs3[],int pos3)
{
  int c;
		for(c=0; c < limit ;c++)
		{
			textcolor(BLACK);
			textbackground(WHITE);

			if( c == pos1 )
				{
					textcolor(RED);
					textbackground(WHITE);
					cprintf(msgs);
				}
			else if( c == pos2 )
				{
					textcolor(RED);
					textbackground(WHITE);
					cprintf(msgs2);
				}
			else if( c == pos3 )
				{
					textcolor(RED);
					textbackground(WHITE);
					cprintf(msgs3);
				 }
			else
				{
					y=wherey();
					  if(y != 2)
						cputs(" ");
					  else
						break;
				 }
		}
}