Thread: conio.c and getch() conflict?

  1. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002

    conio.c and getch() conflict?


    I use DevC++ 4. When i don't include conio.c when compiling a program, getch() gets the character at the instant i press a particular key. But if i include conio.c, then getch() only works if i press enter after pressing a particular key. Why's that? How can i fix this.



  2. #2
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    I don't know about Dev, but under Borland's conio.h, getch() works with no buffering -- a character is accepted everytime you press it. Maybe Dev's getch() conio.c sets everything to line buffering -- everything is accepeted only after the carriage return/line feed character is read (from the Enter key).

    I think there's no conflict in that
    All men are created equal. But some are more equal than others.

    Visit me at

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    But i want to get the character code at the instant the key is pressed, not after pressing enter. And this works without conio.c being included, which i can't figure out why.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    Is this what you mean?
    #include <conio.h>
    #include <stdio.h>
    int main(void) {
    	int letter = 0;
    	while(letter != -1) {
    		if(kbhit()) {
    			letter = getch();
    			putc(letter, stdout);

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas

    Dev C++

    Not sure. In my conio.h, there is this line:

    #ifndef _CONIO_H_
    #define _CONIO_H_
    #define getch getchar

    My conio.c has no reference to getch().

    However, there is a second file: conio_mingw.h. Here is a snippet:

    #ifndef _CONIO_H_
    #define _CONIO_H_
    char* _cgets (char* szBuffer);
    int _cprintf (const char* szFormat, ...);
    int _cputs (const char* szString);
    int _cscanf (char* szFormat, ...);

    int _getch (); //<-this is unbuffered!
    int _getche ();
    int _kbhit ();
    int _putch (int cPut);
    int _ungetch (int cUnget);

    #ifndef _NO_OLDNAMES

    int getch (); //<-this is buffered!

    int getche ();
    int kbhit ();
    int putch (int cPut);
    int ungetch (int cUnget);

    #endif /* Not _NO_OLDNAMES */

    So I am assuming that when the compiler sees your using conio.c, it uses the first conio.h. Otherwise it uses conio_mingw.

    But I'm just guessing there
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  6. #6
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    hey Sebastiani thnx. I got it working now. What i did was open conio.h and delete the line

    #define getch getchar
    and open conio.c and delete the lines

    int getche() {
      int ch;
      ch = getch ();
      printf ("%c\n", ch);
      return ch;

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, 05:15 AM
  3. Clearing input buffer after using getch()
    By milkydoo in forum C++ Programming
    Replies: 3
    Last Post: 07-21-2003, 11:04 PM
  4. Problems with getch()
    By GrNxxDaY in forum C++ Programming
    Replies: 14
    Last Post: 08-12-2002, 02:11 AM
  5. Using getch()
    By pr0ficient in forum Linux Programming
    Replies: 2
    Last Post: 07-26-2002, 05:59 AM