文件操作之fprintf函数的使用

来源:互联网 发布:攻城狮和程序员打油诗 编辑:程序博客网 时间:2024/06/06 00:43
函数fprintf的原型:
int fprintf( FILE *stream, const char *format [, argument]...);
功能:输出格式化数据到流中。多输入到文件中。

参数:
*stream:指向文件结构体
*format:格式控制字符串
argument:参数的选择

返回值:
成功返回字符数。
失败返回负数。

使用实例,来着MSDN:
#include <stdio.h>
#include <process.h>

FILE *stream;

void main( void )
{
 
 int    i =10;
   double fp = 1.5;
  char   s[] = "this is astring";
  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
原创粉丝点击