ansi alternative to this?

This is a discussion on ansi alternative to this? within the C Programming forums, part of the General Programming Boards category; Could someone help me out with this? I'm trying to make sure that the code I'm working on is standard. ...

  1. #1
    Ragman
    Guest

    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) :

    Code:
    while(again)
    {
    ...
        printf("Do it again Y/N?");
    
        c=toupper(getch()); // need ansi alternative to getch here 
        if(c=='N')
        {
    	printf("N\n");
    	again=FALSE;
        }
        else // as long as it's not 'N' or 'n' we continue
    	printf("Y\n");
    }
    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?

    Ragman

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    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
    Ragman
    Guest
    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
    Posts
    9,796
    >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.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Ragman
    Guest
    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, 08:32 AM
  2. ANSI C Reference
    By Stack Overflow in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-09-2005, 10:08 PM
  3. how closely does vc++.net 2003 follow ANSI?
    By krygen in forum C++ Programming
    Replies: 7
    Last Post: 09-22-2004, 07:48 PM
  4. sigaction() and ANSI C
    By awoodland in forum Linux Programming
    Replies: 4
    Last Post: 04-25-2004, 02:48 AM
  5. Is gotoxy ansi?
    By MeneLaus in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 03:48 PM

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