标准IO效率

1、用getc 和utc将标准输入复制到标准输出

 

#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" );

	if(ferror(stdin))
		printf( "innput error!\n" );

	exit(0);
}


2、用fgetc 和 fputc改写这个程序。

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

int main(void)
{
	int 	c;

	while((c = fgetc(stdin)) != EOF )
		if (fputc(c,stdout) == EOF )
			printf( "output error!\n" );

	if(ferror(stdin))
		printf( "innput error!\n" );

	exit(0);
}


 

3、用fgets 和fputs 将标准输入复制到标准输出

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

#define n	100

int main()
{
	char buf[n];

	while( fgets( buf, n, stdin ) != NULL)
		if( fputs( buf,stdout ) == EOF )
			printf( "fputs error!\n" );

	if( ferror(stdin) )
		printf( "input error !\n" );	

	exit(0);
}


长期以来,UNIX 系统使用两种不同的时间值:

1、日历时间。1970年以来的秒数。 time_t数据类型来保存这种时间值。UTC为格里尼治时间值。

2进程时间。也称为cpu时间,用于度量进程使用的中央处理器资源。  进程时间以时钟滴答计算。  可以用 time 命令来度量。

你可能感兴趣的:(标准IO效率)