江湖救急

xkp123 2010-06-22 11:43:14
请教各位高手怎样将一个整型数组保存到一个txt文档中?
...全文
131 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2010-06-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 huanmie_09 的回复:]
// crt_fprintf.c
/* This program uses fprintf to format various
* data and print it to the file named FPRINTF.OUT. It
* then displays FPRINTF.OUT on the screen using the system
* function to in……
[/Quote]
正解。不过把FILE *变量命名为stream不如f或pF好。
huanmie_09 2010-06-22
  • 打赏
  • 举报
回复
// crt_fprintf.c
/* This program uses fprintf to format various
* data and print it to the file named FPRINTF.OUT. It
* then displays FPRINTF.OUT on the screen using the system
* function to invoke the operating-system TYPE command.
*/

#include <stdio.h>
#include <process.h>

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 );
system( "type fprintf.out" );
}
  • 打赏
  • 举报
回复
方法不少:
int fprintf(FILE *stream, const char *format, ...);
上面这函数可以!
size_t fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream);
这个函数也可以做到!
beginsoft_nj 2010-06-22
  • 打赏
  • 举报
回复
fopen(filename,"wb+");
fwrite(buf,1,size,pf);
luzhiwei512 2010-06-22
  • 打赏
  • 举报
回复
你可以参考文件操作
zjf30366 2010-06-22
  • 打赏
  • 举报
回复
yuanzhang198711 2010-06-22
  • 打赏
  • 举报
回复
飘过,就是文件操作嘛,Google!
liumangmaoenen 2010-06-22
  • 打赏
  • 举报
回复
好像有一些对文件读写的函数可以用的吧~

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧