荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: Version (音乐,美的最初与最终), 信区: Program
标  题: getchar()
发信站: 荔园晨风BBS站 (Fri May 30 17:35:52 2003), 站内信件

Run-Time Library Reference

getc, getwc, getchar, getwcharSee Also
Stream I/O Routines | fgetc | _getch | putc | ungetc
Requirements
Routine Required header Compatibility

getc <stdio.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
getwc <stdio.h> or <wchar.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
getchar <stdio.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
getwchar <stdio.h> or <wchar.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the
Introduction.

Libraries

All versions of the C run-time libraries.
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 );
Parameter
stream
Input stream.
Return Value
Returns the character read. To indicate a 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.

Remarks
Each routine 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. For 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

TCHAR.H routine  _UNICODE & _MBCS not defined _MBCS defined _UNICODE
defined
_gettc getc getc getwc
_gettchar getchar getchar getwchar

Requirements
Routine Required header Compatibility
getc <stdio.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
getwc <stdio.h> or <wchar.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win
 XP
getchar <stdio.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
getwchar <stdio.h> or <wchar.h> ANSI, Win 98, Win Me, Win NT, Win 2000,
 Win XP

For additional compatibility information, see Compatibility in the
Introduction.

Libraries

All versions of the C run-time libraries.

Example
/* GETC.C: This program uses getchar to read a single line
 * of input from stdin, places this input in buffer, then
 * terminates the string before printing it to the screen.
 */

#include <stdio.h>

void main( void )
{
   char buffer[81];
   int i, ch;

   printf( "Enter a line: " );

   /* Read in single line from "stdin": */
   for( i = 0; (i < 80) &&  ((ch = getchar()) != EOF)
                        && (ch != '\n'); i++ )
      buffer[i] = (char)ch;

   /* Terminate string with null character: */
   buffer[i] = '\0';
   printf( "%s\n", buffer );
}

Output
Enter a line: This is a test
This is a test

See Also
Stream I/O Routines | fgetc | _getch | putc | ungetc



------------------------------------------------------------------------
--------

Send feedback to Microsoft

? 2001 Microsoft Corporation. All rights reserved.

--
                      *
          *                                  *
                          *             *
                      no more to say
                  ★     just wish you   ★
                            good luck

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.1.50]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店