I am trying to make a program so that you can enter your name, but I want to limit the amount of characters used to 10. This is what i have so far, and when i press backspace on my program, it doesn't delete the previous character but moves the cursor there.
So can anyone help me to make this type of program which works?
#include <stdio.h>
#include <conio.h>
char Name[10];
int Ch = 0;
void NameF()
{
printf("Enter Name : ");
while(Ch < 10)
{
Name[Ch] = getch();
if(Ch > 0 && Name[Ch] == '\b')
{
Ch --;
putch(8);
}
else
putch(Name[Ch]);
if(Name[Ch] == '\r')
break;
Ch++;
}
printf("\nName : %s", Name);
}
void main()
{
NameF();
}