[問題] 想讀取文字檔增減後再輸出

看板C_and_CPP (C/C++)作者 (阿翰)時間15年前 (2010/08/09 11:13), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
遇到的問題: (題意請描述清楚) 目前有個檔案想讀入後,某幾行要增字,而某幾行卻要減少 結束後再輸出程另外一個檔案 例如: input file 4 atoms 1 atom types 0 8.18 xlo xhi 0 8.18 ylo yhi 0 8.18 zlo zhi Atoms 1 1 1.0225 1.0225 1.0225 2 1 3.0675 3.0675 1.0225 3 1 1.0225 3.0675 3.0675 4 1 3.0675 1.0225 3.0675 希望得到的正確結果: 想得到的結果: 8.18 0.00 0.00 0.00 8.18 0.00 0.00 0.00 8.18 Atoms 1.0225 1.0225 1.0225 3.0675 3.0675 1.0225 1.0225 3.0675 3.0675 3.0675 1.0225 3.0675 程式跑出來的錯誤結果: 開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux) C++ 有問題的code: (請善用置底文標色功能) #include <iostream> #include <stdio.h> int main() { FILE *fin, *fout; fin = fopen("Ag001.data","rt"); fout = fopen("agout","w+t"); if(fin==NULL); { printf("Fail To Open File Ag001.data!!"); fclose(fin); fclose(fout); } if(fin!=NULL); { fputs("fopen example",fout); fclose(fin); fclose(fout); } return 0; } 補充說明: 請問如果還要把上下兩個當成矩陣作其它運算該怎麼讀取? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.28.110

08/10 23:36, , 1F
你的兩個if後面為什麼要有;
08/10 23:36, 1F
文章代碼(AID): #1CNt9ktB (C_and_CPP)
文章代碼(AID): #1CNt9ktB (C_and_CPP)