how to make a 'backspace' program in C?
I am creating some library function for print and scan using assembly language and c. Now when am entering datas it is getting print,but the problem is when i press the backspace button the cursor is moving backwards(but not deleting a开发者_JAVA百科nything)..I want the backspace button to work properly(ie,to delete the previous character)
so is there any program for that.Please help me.
The simple, albeit somewhat hackish, way is to just write backspace characters (\b
) to the console.
For example:
#include <stdio.h>
int main()
{
printf("Testing");
fflush(stdout);
printf("\b\b\b");
fflush(stdout);
return 0;
}
But this type of thing should really be handled by your terminal driver. You don't mention what operating system you're targeting in the question.
Output a backspace, space, and backspace:
int c = getchar();
if (c == '\b')
{
printf("\b \b");
fflush(stdout);
}
If the user's press of a backspace was already echoed by the terminal driver then just do this:
int c = getchar();
if (c == '\b')
{
printf(" \b");
fflush(stdout);
}
if u r doing so then would like to tell you one thing abt consoles There are 2 types of consoles , one which can recognize control char. called Active console(Canonical mode) and one which not called row console . Obviously if u r using unix's terminal then u will be given default as Active mode console but u can set it to row mode by executing some commands.
精彩评论