-
getch not wroking...
ive been thinking of ways to use getch() in a menu im makeing so i figured i'd try to use it first and made this:
int mian()
{
char test;
test = getchar();
if(test == a)
{
cout<<"Hello";
}
else
{
cout<<"Bye";
}
}
but when i run it when you press a it justs prints a like if u sed cout until you press enter is it something wrong with my code or my complier (Bloodshed Dev-C++ 4) or maybe i just think getchar does something different then it does.
-
If you are windows then you can use getch() in conio.h
if you are on linux then turn off echo and set the io to read immediately and not wait for enter key. (Check Linux Programming book for how to)
Also dont forget to put single quotes around the a.
-
When I use Bloodshed DEV-C++, I use getche()
-
What kind of console or OS are u using? Linux has echo on sometimes, and certain console thingies, like certain telnet things echo everything no matter what. So...It's either that, or a programming error. I think its the first though.
-
With Dev-C++ include conio_mingw.h. It will allow you to use it.
-
if(test == a)
should be
if(test == 'a')
-
Dude check your main !! It should be int main(), also
if(test == a) -> 'a' is a character ..