• Aucun résultat trouvé

Keyboard and Port 1/0 Routines

Dans le document Language Reference (Page 65-69)

The keyboard and port input/output routines are an extension of the stream routi nes. They let you read from a keyboard or read from or write to an input/output port, such as a printer port. The port input/output routines read and write data in bytes. Some additional options are available with keyboard input/output routines. For example, your program can detect whether a user has typed a acter on the keyboard. You can also choose between echoing char-acters to the screen as the system reads them or reading charchar-acters without echoing. The routines are:

Routine

Reads a string from the keyboard.

Writes formatted data to the screen.

Writes a string to the screen.

Reads formatted data from the keyboard.

Reads a character from the keyboard.

Reads a character from the keyboard and echoes it.

Reads from a specified input port.

Checks for a keystroke at the keyboard.

Writes to a specified output port.

Writes a character to the screen.

Pushes the last character back to the keyboard again so that it becomes the next character read.

The keyboard and port input/output routines are functions in the include file conio.h. These functions perform reading operations from your keyboard, writing operations on your screen, or reading or writing operations on a specified port. The cgets, cscanf, getch, getche, and kbhit functions take input from the keyboard, while cprinH, cputs, putch, and ungetch write to the screen. Redirecting the standard input or standard output streams from the command line redirects the input or output of these functions.

You do not have to open or close the port for the keyboard or screen before you perform an input or output operation. Consequently, there are no open or close routines in this category. The port input/output routines inp and outp read 1 byte at a time from or write 1 byte at a time to the specified port. The keyboard and screen input/output rou-tines allow the reading and writing of strings (cgets and cputs),

for-matted data (cscanf and cprinH), and characters. Several options are available for reading and writing characters.

The putch routine writes a character to the screen. The getch and getche routines read a character from the keyboard. Getche echoes the character back to the screen, and getch does not. The ungetch routine pushes the last character read back to the keyboard. The next read operation on the keyboard begins with that character, the last character typed.

The kbhit routine tells when a key has been struck at the keyboard.

This routine lets you test for keyboard input before you try to read.

Note: The keyboard and screen input/output routines use the corre-sponding DOS system calls to read and write characters. See the IBM Disk Operating System Technical Reference book for the details of the specific system calls. Under OS/2, you may not redirect data to or from other files using these routines.

The keyboard and screen input/output routines always use the console.

Math

The math routines let you perform common mathematical calcu-lations. All math routines (except matherr, the error-handling func-tion) work with floating-point values and thus require floating-point support. See the section on "Floating-Point Support" in Chapter 1 of this book for additional information. The include file math.h gives function declarations for the math routines, except for _clear87, _controI87, _fpreset, and _status87, whose definitions are in the float.h include file.

Calculates an arc cosine.

Calculates an arc sine.

Calculates an arc tangent of one argument.

Calculates an arc tangent of two arguments.

Calculates bessel functions. .

Finds the absolute value of a complex number.

Finds the integer ceiling of a double.

_clear87

Gets and clears a floating-point status word.

Gets an old floating-point control word and sets a new control-word val ue.

Calculates a cosine.

Calculates a hyperbolic cosine.

Converts an IEEE double-precision format to a binary double format.

Converts a binary double format to an IEEE double-precision format.

Calculates an exponential function.

Fi nds an absol ute val ue of a double.

Converts an IEEE single-precision format to binary format (float).

Finds an integer floor of a double.

Finds a remainder.

Converts a binary format (float) to IEEE single-precision format.

Reinitializes the floating-point math package.

Breaks down a double into a mantissa and expo-nent.

Calculates an hypotenuse.

Calculates x times a power of 2.

Calculates a natural logarithm.

Calculates a base 10 logarithm.

Handles math errors.

Breaks down a double into an integer and fractional parts.

Calculates a power.

Calculates a sine.

Calculates a hyperbolic sine.

Finds a square root.

Gets the floating-point status word.

Calculates a tangent.

Calculates a hyperbolic tangent.

The math functions call the matherr routine when errors occur. This routine is defined in the library, but you can redefine it if you want different error-handling procedures. When you define the matherr function, it must conform to the specifications for the matherr function in Chapter 5, "Library Routines."

You need not supply a definition for matherr. If no definition is present, the system returns the default error for each routine. See the reference page for each routine in Chapter 5, "Library Routines,"

for a description of its error return values.

Dans le document Language Reference (Page 65-69)