您的位置:首页 > 其它

fgetc getc getchar fputc putc putchar

2010-12-24 22:48 344 查看
fgetc getc getchar
fputc putc putchar

fgetc
调用方式:
int fgetc( FILE *stream )
功能
Read a character(字符当作unsigned char类型来读取,然后转换为int类型) from a stream。
返回值
Fgetc return the character read as an int or return EOF to indicate an error or end of file. Use feof or ferror to distinguish between an error and an end-of-file condition. If a read error occurs, the error indicator for the stream is set.
实现方式
Implemented only as a function

getc
调用方式
int getc( FILE *stream );
功能
Same as fgetc, but implemented as a function and as a macro
返回值
Return the character read. To indicate an read error or end-of-file condition, getc return EOF.Use ferror or feof to check for an error or for end of file.
实现方式
Implemented as a function and as a macro.调用时,默认使用宏实现。
宏实现:#define getc(_stream) (--(_stream)->_cnt >= 0 /
? 0xff & *(_stream)->_ptr++ : _filbuf(_stream))

getchar
调用方式
int getchar( void )
功能
从标准输入stdin读入一个字符。程序等待你输入的时候,你可以输入多个字符,回车后程序继续执行,但getchar只读入一个字符。
返回值
Return the character read. To indicate an read error or end-of-file condition, getchar returns EOF. Use ferror or feof to check for an error or for end of file.
实现方式
Implemented as a function and as a macro. 调用时,默认使用宏实现。
宏实现:#define getchar() getc(stdin)

fgetcgetc的功能是一样的,但他们还是有区别的
The difference between the first two functions is that getc can be implemented as a macro, whereas fgetc cannot be implemented as a macro. This means three things.
1.The argument to getc should not be an expression with side effects. 因而用宏一般不使用有“副作用”的表达式。
2.Since fgetc is guaranteed to be a function, we can take its address. This allows us to pass the address of fgetc as an argument to another function.
3.Calls to fgetc probably take longer than calls to getc, as it usually takes more time to call a function.

fputc
调用方式
int fputc( int c, FILE *stream )
功能
Write a character to a stream。在将c写入流之前,会强制将c转换为unsigned char。
实现方式
Implemented only as a function
返回值
Return the character written. A return value of EOF indicates an error.

putc
调用方式
int fputc( int c, FILE *stream )
功能
跟fput的一样
实现方式
Implemented as a function and a macro.调用时,默认使用宏实现。
宏实现:#define putc(_c,_stream) (--(_stream)->_cnt >= 0 /
? 0xff & (*(_stream)->_ptr++ = (char)(_c)) : _flsbuf((_c),(_stream)))
返回值
Return the character written. A return value of EOF indicates an error.

putchar
调用方式
int putchar( int c )
功能
Write a characte to stdout.
实现方式
Implemented as a function and a macro 调用时,默认使用宏实现
宏实现:#define putchar() putchar(stdout)
返回值
Return the character written. A return value of EOF indicates an error.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐