精華區beta NCTU-STAT95G 關於我們 聯絡資訊
※ [本文轉錄自 NCTU-STAT94G 看板] 作者: catherinejoy (whatcanisay) 看板: NCTU-STAT94G 標題: [心得] fprintf 改檔名自動輸出 時間: Thu Oct 26 13:26:13 2006 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.114.200 ※ 編輯: catherinejoy 來自: 140.113.114.200 (10/26 13:29)
littlehana:強者 10/26 17:11
※ 編輯: catherinejoy 來自: 140.113.197.227 (10/27 00:33) ※ 編輯: catherinejoy 來自: 140.113.197.227 (10/27 00:34)
catherinejoy:強者是泰賓學長 都是他教導我的 10/27 00:34
mangogogo:借轉 10/27 12:51
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.114.78 > -------------------------------------------------------------------------- < 作者: 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