声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 7521|回复: 4

[共享资源] 关于fprintf的用法

[复制链接]
发表于 2008-10-6 17:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
fid = fopen('exp.txt','w');
        fprintf(fid,'%6.2f  %12.8f\n',y);
        fclose(fid);
关于fprintf的用法,可以详细的介绍吗,而且fprintf读数是按列读呢,还是按行???红色部分的格式能给个完全的表格吗
回复
分享到:

使用道具 举报

发表于 2008-10-6 19:22 | 显示全部楼层

回复 楼主 蜜雪儿 的帖子

什么意思
你自己试一下就知道了
发表于 2008-10-6 19:44 | 显示全部楼层
函数名: fprintf
  功 能: 传送格式化输出到一个流中
  用 法: int fprintf(FILE *stream, char *format[, argument,...]);
  返回值:成功时返回转换的字节数,失败时返回一个负数
  程序例:
  /* Program to create backup of the
  AUTOEXEC.BAT file */
  #include <stdio.h>
  int main(void)
  {
  FILE *in, *out;
  if ((in = fopen("\\AUTOEXEC.BAT", "rt"))
  == NULL)
  {
  fprintf(stderr, "Cannot open input \
  file.\n");
  return 1;
  }
  if ((out = fopen("\\AUTOEXEC.BAK", "wt"))
  == NULL)
  {
  fprintf(stderr, "Cannot open output \
  file.\n");
  return 1;
  }
  while (!feof(in))
  fputc(fgetc(in), out);
  fclose(in);
  fclose(out);
  return 0;
  }
发表于 2008-10-6 20:44 | 显示全部楼层

回复 楼主 蜜雪儿 的帖子

自己查下matlab帮助就知道了,你说的应该就是这个例子吧。



  1. Example 1


  2. Create a text file called exp.txt containing a short table of the exponential function. (On Windows platforms, it is recommended that you use fopen with the mode set to 'wt' to open a text file for writing.)
  3. x = 0:.1:1;
  4. y = [x; exp(x)];
  5. fid = fopen('exp.txt', 'wt');
  6. fprintf(fid, '%6.2f %12.8f\n', y);
  7. fclose(fid)



  8. Now examine the contents of exp.txt:
  9. type exp.txt
  10.    0.00    1.00000000
  11.    0.10    1.10517092
  12.        ...
  13.    1.00    2.71828183
复制代码
发表于 2008-10-6 20:46 | 显示全部楼层

回复 板凳 科技在线 的帖子

这个是c语言吧?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-18 11:49 , Processed in 0.077252 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表