![]() |
C - Entwicklung Character - StreamIO Homepage von PS-Trainer - C-Entwicklung - Stream-IO - an PS-Trainer |
|
| StreamIO | Data Stream Input & Output |
| Character tables | Tables of common character sets |
| getc, getwc, getchar, getwchar | Read a character from a stream (getc, getwc), or get a character from stdin (getchar, getwchar). |
| _getch,
_getche |
Get a character from the console without echo (_getch) or with echo (_getche). |
| putc, putwc, putchar, putwchar | Writes a character to a stream (putc, putwc) or to stdout (putchar, putwchar). |
| _putch | Writes a character to the console. |
| _ungetch
|
Pushes back the last charcter read from the console. |
| getc, getwc, getchar,
getwchar Read a character from a stream (getc, getwc), or get a character from stdin (getchar, getwchar). int getc( FILE *stream ); wint_t getwc( FILE *stream ); int getchar( void ); wint_t getwchar( void );
Remarks Each of these routines reads a single character from a file at the current position and increments the associated file pointer (if defined) to point to the next character. In the case of getc and getwc, the file is associated with stream (see Choosing Between Functions and Macros). Routine-specific remarks follow. Routine Remarks getc Same as fgetc, but implemented as a function and as a macro. getwc Wide-character version of getc. Reads a multibyte character or a wide character according to whether stream is opened in text mode or binary mode. getchar Same as _fgetchar, but implemented as a function and as a macro. getwchar Wide-character version of getchar. Reads a multibyte character or a wide character according to whether stream is opened in text mode or binary mode. Generic-Text Routine Mappings
Subject: Stream I/O Routines Keywords: See Also fgetc, _getch, putc, ungetc |
|||||||||||||||||||||||||||||||
| Return Value Each of these functions returns the character read. To indicate an read error or end-of-file condition, getc and getchar return EOF, and getwc and getwchar return WEOF. For getc and getchar, use ferror or feof to check for an error or for end of file. Parameter
|
|||||||||||||||||||||||||||||||
|
Example #include <stdio.h> void main( void ) printf( "Enter a line: " ); /* Read in single line from
"stdin": */ /* Terminate string with null
character: */ |
| _getch, _getche Get a character from the console without echo (_getch) or with echo (_getche). int _getch( void ); int _getche( void );
Remarks The _getch function reads a single character from the console without echoing. _getche reads a single character from the console and echoes the character read. Neither function can be used to read CTRL+C. When reading a function key or an arrow key, _getch and _getche must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code. Subject: Console and Port I/O Routines Keywords: See also _cgets, getc, _ungetch |
|||||||||
| Return Value Both _getch and _getche return the character read. There is no error return. |
|||||||||
|
Example #include <conio.h> void main( void ) _cputs( "Type 'Y' when
finished typing keys: " ); _putch( ch ); |
| putc, putwc, putchar,
putwchar Writes a character to a stream (putc, putwc) or to stdout (putchar, putwchar). int putc( int c, FILE *stream ); wint_t putwc( wint_t c, FILE *stream ); int putchar( int c ); wint_t putwchar( wint_t c );
Remarks The putc routine writes the single character c to the output stream at the current position. Any integer can be passed to putc, but only the lower 8 bits are written. The putchar routine is identical to putc( c, stdout ). For each routine, if a read error occurs, the error indicator for the stream is set. putc and putchar are similar to fputc and _fputchar, respectively, but are implemented both as functions and as macros (see Choosing Between Functions and Macros). putwc and putwchar are wide-character versions of putc and putchar, respectively. Generic-Text Routine Mappings
Subject: Stream I/O Routines Keywords: See also fputc, getc |
|||||||||||||||||||||||||||||||
| Return Value Each of these functions returns the character written. To indicate an error or end-of-file condition, putc and putchar return EOF; putwc and putwchar return WEOF. For all four routines, use ferror or feof to check for an error or end of file. Parameters
|
|||||||||||||||||||||||||||||||
| Example /* PUTC.C: This program uses putc to write buffer * to a stream. If an error occurs, the program * stops before writing the entire buffer. */ #include <stdio.h> void main( void ) ch = 0; |
|
_putch
Remarks The _putch function writes the character c directly (without buffering) to the console. Subject: Console and Port I/O Routines Keywords: See also _cprintf, _getch |
||||||
| Return Value The function returns c if successful, and EOF if not. Parameter
|
||||||
|
Example #include <conio.h> void main( void ) _cputs( "Type 'Y' when
finished typing keys: " ); _putch( ch ); |
| _ungetch Pushes back the last charcter read from the console. int _ungetch( int c );
Remarks The _ungetch function pushes the character c back to the console, causing c to be the next character read by _getch or _getche. _ungetch fails if it is called more than once before the next read. The c argument may not be EOF. Subject: Console and Port I/O Routines Keywords: See also _cscanf, _getch |
||||||
| Return Value _ungetch returns the character c if it is successful. A return value of EOF indicates an error. Parameter
|
||||||
| Example /* UNGETCH.C: In this program, a white-space delimited * token is read from the keyboard. When the program * encounters a delimiter, it uses _ungetch to replace * the character in the keyboard buffer. */ #include <conio.h> void main( void ) |
| Aktuelle Daten dieser Seite | Letzte Änderung: |
| |