Create your own 'backspace' function in C


Backspace Function:

Backspace function it is used to delete the characters just like the keyboard button do.

INBUILT FUNCTIONS USED :

1.wherex() and wherey() functions.
2.gotoxy(x,y) function


WHEREX() and WHEREY() FUNCTIONS:

where function is used to locate the current location of a cursor in run time of program.
syntax:
int wherex();
int wherey();

wherex and wherey will give the current location of cursor with respect to x and y respectively............


GOTOXY(x,y) FUNCTION:

gotoxy function is used to move the cursor position according to user during runtime.
syntax
gotoxy(x,y);

Only with the help of this position function we are going to create the backspace function:

PROGRAM AS FOLLOWS:

#include<stdio.h>
#include<conio.h>
int main()
{
int e,f,c=0,a,i=0;
char b[20];
clrscr();
printf("enter ");
while(c!=1)
{
a=getch();
if(a!=13 && a!=8)
{
printf("*");
b[i]=a;
i++;
}
else if(a==8)
{
e=wherex();
f=wherey();
gotoxy(e-1,f);
printf(" ");
gotoxy(e-1,f);
i--;
b[i]='\0'   ;
}
else
{
c=1;
}
}
b[i]='\0';
//printf("%d",a);
printf("%s",b);
getch();
return 0;
}



Hope u learn something new today. For any doubt pleae comment your query to me.

Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...
 
Posts RSSComments RSSBack to top
© 2013 Updated Tech News Results and Reviews