Is it possible to limit user input to say a few number of characters, or even just 1?
for example, when the user enters 1 character, the program will immediately move on to a next line of code?
Printable View
Is it possible to limit user input to say a few number of characters, or even just 1?
for example, when the user enters 1 character, the program will immediately move on to a next line of code?
getch() or getche().
This is from an old post of mine:
It doesn't look very nice but it works fine.
If you want more than 1 character use a for to loop each character and print each character at the time which it was given.Code:#include <stdio.h>
#include <conio.h>
int main()
{
int c;
c = getch();
printf("%c\n", c);
.....statements....
return 0;
}
for more than one character you could use:
fgets( string, 10, stdin);
that would accept only the first nine characters from the keyboard, and replsce the last character with a '\0'.
Only useful if you're entering a string, other wise I'd go with the 'for' loop.