Conio.h

From Wikipedia, the free encyclopedia

The correct title of this article is conio.h. The initial letter is shown capitalized due to technical restrictions.

conio.h is a header file used in old MS-DOS compilers, to create TUI interfaces, however, it is not part of the C programming language, the C standard library, ISO C or by POSIX.

This header declares several useful library functions for performing "console input and output" from a program. Most C compilers that target DOS, Windows 3.x, Phar Lap, DOSX, OS/2, or Win32 have this header and supply the concomitant library functions in the default C library. Most C compilers that target UNIX and Linux do not have this header and do not supply the concomitant library functions.

The library functions declared by conio.h vary significantly from compiler to compiler. As originally implemented in Microsoft's Visual C++ the various functions mapped directly to the first few DOS int 21h functions. But the library supplied with Turbo C++ and Borland C++ did not use the DOS API but instead accessed video RAM directly for output and used BIOS interrupt calls.

Compilers that targetted non-DOS operating systems, such as Linux, Win32 and OS/2, provided yet more different implementations of these functions.

[edit] Member functions

int kbhit(void) Determines if a keyboard key was pressed.
int ungetch(int c) Puts the character c back into the keyboard buffer.
int getch(void) Reads a character directly from the console without buffer, and without echo.
int getche(void) Reads a character directly from the console without buffer, but with echo.
int putch(int c) The _putch function writes character c to the console, without buffering. If successful, returns c. Otherwise, returns EOF.
char *_cgets(char *buffer) Gets a string from the console and stores it in the array pointed to by buffer. buffer[0], must contain the maximum length, in characters, of the string to be read. The array's second element, buffer[1], is where. _cgets stores the string's actual length _cgets reads characters until it reads the carriage-return/ line-feed combination or the specifed maximum number of characters.
int _cprintf(const char *format, arg0,... argn) Formats and prints a string directly to the console.
int _cputs(const char *string) Outputs a string directly to the console.
int _cscanf(char *format, arg0,... argn) Reads and formats values directly from the console.

[edit] See also

[edit] References