设为首页 加入收藏

TOP

Fwrite和fprintf之间的区别(二)
2014-04-06 17:40:28 来源: 作者: 【 】 浏览:251
Tags:Fwrite fprintf 之间 区别

 

  二、 fprintf函数介绍

  #include

  int fprintf( FILE *stream, const char *format, ... );

  功能:根据指定的format(格式)发送信息(参数)到由stream(流)指定的文件

  返回值:若成功则返回输出字符数,若输出出错则返回负值。

  #include

  #include

  FILE * stream;

  int 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);

  return 0;

  }

  结果:

  [root@f8s fprintf_test]# gcc fprintf_test.c -o fprintf_test

  [root@f8s fprintf_test]# ./fprintf_test

  [root@f8s fprintf_test]# cat fprintf.out

  this is a string

  10

  1.500000

  [root@f8s fprintf_test]#

        

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇BrainFuck的编译器官方版发布 下一篇8.2.2 指针操作符

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: