码迷,mamicode.com
首页 > 其他好文 > 详细

getcin_to_putcout.c

时间:2015-04-26 13:57:03      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int c;
	while((c = getc(stdin)) != EOF)
		if(putc(c,stdout) == EOF){
			printf("output error\n");
			exit(1);
		}
		
	if(ferror(stdin))
	{
		printf("input error\n");
		exit(1);
	}	
	
	return 0;
		
}
getc函数:
int getc(FILE *stream);  //从stream流获取并返回下一个字符,如果打得到文件尾返回EOF。stream是一个文件指针

putc函数:
int putc(int c, FILE *stream); //输入一个字符到指定流中,参数c表示要输入的位置,参数stream为要输入的流。正确返回 输入的字符,否则返回EOF。


EOF:

EOF 是一个内置宏,表示文件结束符。EOF的值通常是-1。shell终端中表示为Ctrl+D。

ferror函数:
int ferror(FILE *stream); //检测流中的错误。如果stream没有发生错误,返回0,否则返回一个非零值。


getcin_to_putcout.c

标签:

原文地址:http://blog.csdn.net/u011641885/article/details/45286847

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!