Thread: Alternative for getch() as conio.h is not official

  1. #1
    Registered User
    Join Date
    Jun 2015
    Location
    Delhi
    Posts
    35

    Alternative for getch() as conio.h is not official

    If I use scanf() to read standard single character input then ENTER is needed to read next character, in case of getchar() it echoes the input on screen, is there anything which takes input without ENTER being pressed repeatedly and doesn't echo the input?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, there is no provision for this in the standard, so whatever you use will be non-standard.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2015
    Location
    Delhi
    Posts
    35
    any non-standard method which you can suggest? all I get is "implicit declaration of function ‘getch: undefined reference to `getch'
    collect2: error: ld returned 1 exit status’"

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    What compiler/IDE are you using? I'm assuming your OS is Windows (if not, let us know because this will effect the answers we give).

    You can try opening "conio.h" and see if "getch()" is included in there. Some implementations define it slightly different, such as with a leading underscore: "_getch()"

    You can also find OS-specific code through a simple web search - for instance, I found this through a quick search: An alternate to using getch() - C++ Forum

    You might also consider using a library such as curses (pdcurses for Windows). This is especially good if you plan on doing other kinds of trickery with the console.

  5. #5
    Registered User
    Join Date
    Jun 2015
    Location
    Delhi
    Posts
    35
    I am using linux & the compiler is gcc.

  6. #6

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by smrtshrm View Post
    I am using linux & the compiler is gcc.
    Well, you can pretty much discard all of the advice I gave then (except the curses option).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. conio.h, getch(), getche()
    By jackson6612 in forum C++ Programming
    Replies: 1
    Last Post: 05-19-2011, 07:30 PM
  2. alternative for getch()
    By PlanetCoder in forum C Programming
    Replies: 1
    Last Post: 06-14-2006, 09:33 PM
  3. any alternative for getch() ?
    By kiss_psycho in forum C++ Programming
    Replies: 7
    Last Post: 02-28-2003, 09:55 AM
  4. Replies: 0
    Last Post: 11-01-2002, 11:56 AM
  5. conio.c and getch() conflict?
    By Nutshell in forum C Programming
    Replies: 5
    Last Post: 10-12-2002, 01:01 AM