getch not wroking...

This is a discussion on getch not wroking... within the C++ Programming forums, part of the General Programming Boards category; ive been thinking of ways to use getch() in a menu im makeing so i figured i'd try to use ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    16

    Question 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.
    • 0927
    • a.k.a 0 9 two 7

  2. #2
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49
    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.
    Ivan

  3. #3
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47
    When I use Bloodshed DEV-C++, I use getche()

  4. #4
    31173 h4x0r gnu-ehacks's Avatar
    Join Date
    Nov 2001
    Posts
    556
    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.
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    With Dev-C++ include conio_mingw.h. It will allow you to use it.

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    if(test == a)

    should be

    if(test == 'a')
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User programmer's Avatar
    Join Date
    Oct 2001
    Posts
    22
    Dude check your main !! It should be int main(), also
    if(test == a) -> 'a' is a character ..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 04:15 AM
  3. Pause a C program without getch()
    By swgh in forum C Programming
    Replies: 4
    Last Post: 02-20-2006, 10:24 AM
  4. Difference between getch() and getchar()
    By codec in forum C Programming
    Replies: 4
    Last Post: 04-04-2004, 01:34 AM
  5. Clearing input buffer after using getch()
    By milkydoo in forum C++ Programming
    Replies: 3
    Last Post: 07-21-2003, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21