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?
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?
Only by the cross are you saved...
getch() or getche().
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
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.