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)
fgetc和getc的功能是一样的,但他们还是有区别的:
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.
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)
fgetc和getc的功能是一样的,但他们还是有区别的:
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.
相关文章推荐
- 非格式化输入输出getc、fgetc、getchar、putc、fputc、putchar
- 《c和指针》笔记--梳理一下fgetc,getc,getchar,fputc,putc,putchar....
- fgetc,getc,getchar,fputc,putc,putchar总结
- fgetc,getc,getchar,fputc,putc和putchar函数的介绍及易犯的错误
- 5.6 getc/putc、fgetc/fputc和getchar/putchar-流的单字符读写
- Linux C 文件输入输出函数 fopen()、getc()/fgetc()、putc()/fputc()、fclose()、fprintf()、fscanf()、fgets()、fputs()、fseek()、ftell()、fgetpos()、fsetpos() 详解
- C语言中fgetc、fputc和getc、putc的区别是什么
- C语言中文件的读写(fputc和fgetc)(putchar和getchar)
- C语言中fgetc、fputc和getc、putc的区别是什么
- fgets, fputs, ferror, feof, stdin, stdout, EOF, fopen, fclose, fgetc, fputc, getchar, putchar
- 输入和获取字符的使用(putchar,getchar,puts,gets,fputc,fgetc,fscanf,fprintf)
- C语言中fgetc、fputc和getc、putc的区别是什么
- 【C语言天天练(十八)】字符/字符串输入函数fgetc、fgets、getc、getchar和gets
- 文件内容操作篇clearerr fclose fdopen feof fflush fgetc fgets fileno fopen fputc fputs fread freopen fseek ftell fwrite getc getchar gets
- 区分C语言中getch、getche、fgetc、getc、getchar、fgets、gets
- 区分C语言中getch、getche、fgetc、getc、getchar、fgets、gets
- fgetc、getc、getchar、scanf比较
- 文件内容操作篇clearerr fclose fdopen feof fflush fgetc fgets fileno fopen fputc fputs fread freopen fseek ftell fwrite getc getchar gets
- fgetc, fgets, getc, getchar, gets, ungetc ---- input of characters and strings
- 区分C语言中getch、getche、fgetc、getc、getchar、fgets、gets函数 .