I can't get the backspace key to work properly. When typing the name it appears to be fine, but once I hit enter and it is printed out it doesn't look the way it should.
Ex.
"Davie[BS]d" will produce Davi once I hit enter
Ex.
"Davie[BS]d" will produce Davi once I hit enter
Code:
#include <stdio.h>
#include <conio.h>
char name[32];
void main()
{
int i = 0;
while (name[i - 1] != 13)
{
name[i] = getch();
//Check for Backspace.
if (name[i] == 8)
{
i--;
printf("\b%c",0,8);
name[i] = 0;.
}
else { printf("%c%c", name[i]); }
i++;
}
name[i] = 0;
printf("\nThank you %s", name);
getch();
}