getchar与putchar(借鉴别人的观点)
来源:互联网 发布:模拟退火算法实例ppt 编辑:程序博客网 时间:2024/06/05 17:59
getchar函数,不需要参数,返回值是整型,功能是从标准输入的缓冲区“pop”出一个字符,而因为字符存储时是存储的字符的ASCII码,也就是一数字,所以getchar返回的整数就是这个字符的ASCII码;而因为C99要求getchar在遇到EOF时返回EOF,而EOF一般为-1,所以用char型数据类型无法标示,于是决定采用返回整型的实现方式。
7.19.7.6 The getchar function
Synopsis
1 #include <stdio.h>
int getchar(void);
Description
2 The getchar function is equivalent to getc with the argument stdin.
Returns
3 The getchar function returns the next character from the input stream pointed to by
stdin. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
getchar returns EOF. If a read error occurs, the error indicator for the stream is set and
getchar returns EOF.
putchar函数,需要一个整型参数,返回整型;执行时,函数将传入的整型参数类型转换为unsigned char,并将其写入标准输出的缓冲区,然后将这个字符返回,(或者是EOF),用整型的原因同上。
7.19.7.9 The putchar function
Synopsis
1 #include <stdio.h>
int putchar(int c);
Description
2 The putchar function is equivalent to putc with the second argument stdout.
Returns
3 The putchar function returns the character written. If a write error occurs, the error
indicator for the stream is set and putchar returns EOF.
正如上面C99文档中提到的,一般的实现中,getchar和putchar一般都是宏,最终的调用是fgetc和fputc,针对标准输入和标准输出。所有的操作仅对于缓冲区的一个字符,或者说一个字节这么大的数据。s
- getchar与putchar(借鉴别人的观点)
- getchar()与putchar()
- putchar()与getchar()
- getchar()与putchar()的简单使用
- 有关putchar与getchar的知识
- 输入输出的优化(getchar与putchar)
- getchar 与 putchar
- getchar( )与putchar( )
- getchar 与 putchar
- getchar与putchar
- getchar与putchar
- 关于putchar与getchar
- 问个关于getchar与putchar的问题!(转载)
- C语言中getchar与putchar的使用
- putchar与getchar以及对缓冲区的理解
- 【C++】getchar putchar的用法
- getchar和putchar的使用方法
- getchar 和putchar的注意事项
- Activity学习
- Linux中Workqueue机制分析
- interview 几点总结
- 外观模式
- [Qt教程] Inside Qt Series (六):元对象编译器 – Meta Object Compiler (moc)moc, Qt教程
- getchar与putchar(借鉴别人的观点)
- python 文件代码走读。
- SoundTouch音频处理库源码分析及算法提取(2)
- Android的CTS测试
- SoundTouch音频处理库源码分析及算法提取(3)
- log4j.properties 使用
- "mkimage" command not found - U-Boot images will not be built
- SoundTouch音频处理库源码分析及算法提取(4)
- ubuntu JDK找不到包