C language provides many ways to input a character. We can use the
traditional scanf() function to input a character. However there are
three special character input functions in c, these are:
1. getch(): To input a single character form user.
char ch;
ch=getch();
However this code will not show the typed character ,but still typed character is stored to ch variable;
2. getche() : Again only single character can be inputed like getch() but this time , it will echo(displays) the typed character
char ch;
ch=getche();
3. getchar(): This works similar to scanf() function, i.e. allows user to type more than one character but only the first one will be accepted as input.
char ch;
ch=getchar();
In all the three cases you can check the inputed value to ch by the statement :
printf("Character inputed is %c",ch);
or
putchar(ch);
1. getch(): To input a single character form user.
char ch;
ch=getch();
However this code will not show the typed character ,but still typed character is stored to ch variable;
2. getche() : Again only single character can be inputed like getch() but this time , it will echo(displays) the typed character
char ch;
ch=getche();
3. getchar(): This works similar to scanf() function, i.e. allows user to type more than one character but only the first one will be accepted as input.
char ch;
ch=getchar();
In all the three cases you can check the inputed value to ch by the statement :
printf("Character inputed is %c",ch);
or
putchar(ch);