Hey, I'm a high school student who is fairly programming and I was curious as to how to input a single character without entered an End of Data marker (e.g. newline character/Enter)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
char ch;
switch (toupper(getchar()))
{
case 'A':
puts("You entered the letter A");
break;
case 'B':
puts("You entered the letter B");
break;
default :
puts("You entered niether A nor B");
break;
}
system("pause");
}
The problem I found was that
fgetc(),scanf(),fscanf(),getchar() all require you to press the Enter button in order for you to retrieve you input. I would like function or solution which allows me to input the character without pressing enter.
A practical example as to what I mean is in the command prompt the command pause does not force you to press enter, it waits for you to input a character and discards it.
#include <stdlib.h>
int main()
{
system("pause");
}
I would like a solution to do exactly this except I do not want to discard the character entered.
(sorry if I was repetitive or redundant)