Thread: ansi alternative to this?

  1. #1

    ansi alternative to this?

    Could someone help me out with this? I'm trying to make sure that the code I'm working on is standard. I'm using VC++6.

    Here's the snippet in question(btw I'm still just a newb) :

        printf("Do it again Y/N?");
        c=toupper(getch()); // need ansi alternative to getch here 
        else // as long as it's not 'N' or 'n' we continue
    It's just the controlling loop in main. The ... represents the rest of the function calls that do the work of the program. 'again' was previously defined as TRUE before the loop started.

    What I'm concerned with is 'getch()' since it is not ansi. All I want is for the user to be able to hit 'N' or 'n' to quit and basicly any other key to continue, but I don't want them to have to hit [enter] after they choose. All I've been able to learn how to do this is either use getch() or kbhit(), neither of which I want.

    I tried searching the boards the other day and google tonight but wasn't sure how to best refine the search. At google I mostly found descriptions of it's non-portability but no alternatives other than to use getchar.

    Is this an age-old newbie question or am I just being obtuse and narrow minded?


  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Bangalore, India
    Most DOS like OS's support 'getch()'. On UNIX, the CURSES library is supported by most flavors, and it inturn supports 'getch()'. So, do as vVv said ......

  3. #3
    To be honest I was hoping for better news, maybe a function that could be written that would mimic the ability of getch or just some ansi way of getting unbuffered input in C. Thanks for the advice guys.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >maybe a function that could be written that would mimic the
    >ability of getch or just some ansi way of getting unbuffered input in C.
    How input is buffered is determined by the operating system, not your C program. This is one of the reasons that getch is nonstandard, it requires platform specific features to get the effect of unbuffered input on operating systems that mostly have buffered input.

    My best code is written with the delete key.

  5. #5
    I found a transcript last night discussing this very thing and I finally came to realize it's not just a simple thing that is missing or is just different on other platforms. thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to know if my code is ANSI strict ?
    By jabka in forum C Programming
    Replies: 1
    Last Post: 10-19-2007, 07:32 AM
  2. ANSI C Reference
    By Stack Overflow in forum A Brief History of
    Replies: 1
    Last Post: 03-09-2005, 10:08 PM
  3. how closely does 2003 follow ANSI?
    By krygen in forum C++ Programming
    Replies: 7
    Last Post: 09-22-2004, 06:48 PM
  4. sigaction() and ANSI C
    By awoodland in forum Linux Programming
    Replies: 4
    Last Post: 04-25-2004, 01:48 AM
  5. Is gotoxy ansi?
    By MeneLaus in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 02:48 PM