I have a little problem with one of my assignments. It's about a problem that goes as follows:
Using the Switch statement, write a program that reads values until the ENTER key is pressed. If the characters "Newline", "Tab", or "Backspace" are pressed, output their names.
Here's what I did so far.
int main(){
char x;
x=getchar();
while(x!='\r')
{
switch (x)
{
case '\t':
printf("Tab!");
break;
case '\n':
printf("Newline!");
break;
case '\b':
printf("Backspace!");
break;
default: break;
}
x = getchar();
}
/* switch(x){
case '\r': break;
case '\t': printf("Tab!");
case '\n': printf("Newline!");
case '\b': printf("Backspace!");
default: x=getch();
} */
return 0;
}
My problem is that every time I read a character using getch()
or scanf()
I press enter, so... the program doesn't do much. Do you have any ideas on how I could resolve this problem? Also isn't Newline same key as Enter?
I am using MinGW64 in Windows 10 and VScode as the IDE.