printf&fprintf比较

来源:百度文库 编辑:神马文学网 时间:2024/04/30 12:01:06
fprintf是用于文件操作的,原型是int fprintf( FILE *stream, const char *format [, argument ]...);

举例用法:
#include
#include

FILE *stream;

void main( void )
{
int i = 10;
double fp = 1.5;
char s[] = "this is a string";
char c = '\n';

stream = fopen( "fprintf.out", "w" );
fprintf( stream, "%s%c", s, c );
fprintf( stream, "%d\n", i );
fprintf( stream, "%f\n", fp );
fclose( stream );
system( "type fprintf.out" );
}

屏幕输出:

this is a string
10
1.500000

printf就是在屏幕打印出一段字符串来啊
原型是int printf( const char *format [, argument]... );
是标准输出。