I'm developing a program that uses malloc
and realloc
functions to increment the pointer buffer in real-time while the user is typing a string.
The problem is, that I'd like to prevent the user from hitting Backspace to correct the input.
Is it possible to block Blackspace key somehow in C while using getche()
?
My final program will have two inputs: one without Backspace (you can't go back), and another with Backspace. (you can correct the input and then press Enter).
char *szString;
char *tmp;
int i = 0;
char c;
szString = '�';
szString = malloc(1);
printf("Enter a string: ");
while ((c = getche()) != 'r')
{
if(c = 0x08) // BackSpace
{
//
}
szString[i] = c;
i++;
tmp = realloc(szString, i+1);
szString = tmp;
}
szString[i] = '�';
printf("nYou typed: %s", szString);
Aucun commentaire:
Enregistrer un commentaire