作者mangogogo (mangogo)
看板NCTU-STAT95G
标题[转录]Re: [心得] fprintf 改档名自动输出
时间Fri Oct 27 12:53:21 2006
※ [本文转录自 NCTU-STAT94G 看板]
作者: holder319 (大头) 看板: NCTU-STAT94G
标题: Re: [心得] fprintf 改档名自动输出
时间: Fri Oct 27 11:51:07 2006
※ 引述《catherinejoy (whatcanisay)》之铭言:
若你把副档名改成.cpp,然後在开头 include "iostream" "fstream" "cstring",
那下面的code会更简洁,输出输入也不再需要手动设定格式,一切有预设值自动化.
(当然,做文字处理时你也可以include "string" 然後跟 "cstring" 交叉转换使用)
: main 里
: //export_txt('D:/2006_fall/NHRI','delA',ans,del,item);
: printf("Please input the FILE NAME:\n");
: scanf("%s",&filename);//输入档名开头
: for(i=0;i<del;i++){
: sprintf(filename,"%s_%d",filename,i);//filename_i.txt
: //path="D:/2006_fall/NHRI/i";
: sprintf(path,"%s/%d","D:/2006_fall/NHRI",i);//也可以改路径
: export_txt(path,filename,ans,del,item);
: printf("\n%s.txt is OK!!!\n",filename);
: }//end for i
: header
: void export_txt(char *path,char *FileName,double **ans,int nrow, int ncol){
: char Name[1024];
: int i,j;
: sprintf(Name,"%s/%s.txt",path,FileName);
: out = fopen(Name,"w");
: for(i=0;i<nrow;i++){
: fprintf(out,"%d\t",i+1);
: for(j=0;j<ncol;j++){
: fprintf(out,"%3.0lf\t",ans[i][j]);
: }//end for j
: fprintf(out,"\n");
: }//end for i
: }
: 好 请享用...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.212.111
※ 编辑: holder319 来自: 140.113.212.111 (10/27 11:52)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.114.78