標題:

C++程式修改陣列大小超過10000

發問:

下面的程式 A是a.txt的列數不過A的列數超過10000 (有幾十萬)有辦法把陣列裡的數值超過10000嗎請問要怎麼修改謝謝#include #include #include #include #define A 10000 /* a 檔案中的列數 */#define B 1000 /* b 檔案中的列數 */int main() { int i, j; char x[10000]; /* 宣告字元陣列 x */ float z[10000]; /*... 顯示更多 下面的程式 A是a.txt的列數 不過A的列數超過10000 (有幾十萬) 有辦法把陣列裡的數值超過10000嗎 請問要怎麼修改 謝謝 #include #include #include #include #define A 10000 /* a 檔案中的列數 */ #define B 1000 /* b 檔案中的列數 */ int main() { int i, j; char x[10000]; /* 宣告字元陣列 x */ float z[10000]; /* 宣告浮點數陣列 y */ int b[10000], y[10000]; /* 宣告整數陣列 b, y */ FILE *in1, *in2, *out; /* 宣告檔案指標變數 */ out = fopen("c.txt","w"); /* 將要寫入到 c.txt */ in1 = fopen("a.txt","r"); /* a.txt有 A 列 */ in2 = fopen("b.txt","r"); /* b.txt有 B 個數值 */ if( in1 == NULL || in2 == NULL) { printf("檔案開啟失敗"); return 0; } for ( i = 0; i < A; i++ ) /* a 檔案輸入到 x, y, z 陣列中 */ fscanf( in1, "%s %d %f", &x[i], &y[i], &z[i] ); for ( j = 0; j < B; j++ ) /* a 檔案輸入到 x, y, z 陣列中 */ fscanf( in2, "%d", &b[j] ); for( j = 0; j < B; j++ ) for( i = 0; i < A; i++ )/* 找出 b 中數字 bj 為 a 中字元為 'A' 介於 bj-4,bj+3 內的數值 */ if( x[i]='A' && ( y[i] >= b[j] - 4 ) && ( y[i] <= b[j] + 3 ) ) fprintf(out,"%d %.1f ",y[i],z[i]); system("pause"); return 0; } 更新: 落單滴候鳥 的程式碼怪怪的... 可以請問怎麼改成全域變數嗎?? 3Q

最佳解答:

aa.jpg

 

此文章來自奇摩知識+如有不便請留言告知

為何要將全部的檔案讀取到陣列呀 為何不用邊讀邊比對的方法呢? #include #include #include #include int main() { int i, j; char x; /* 宣告字元陣列 x */ float z; /* 宣告浮點數陣列 y */ int b, y; /* 宣告整數陣列 b, y */ FILE *in1, *in2, *out; /* 宣告檔案指標變數 */ out = fopen("c.txt","w"); /* 將要寫入到 c.txt */ in1 = fopen("a.txt","r"); /* a.txt有 A 列 */ in2 = fopen("b.txt","r"); /* b.txt有 B 個數值 */ if( in1 == NULL || in2 == NULL) { printf("檔案開啟失敗"); return 0; } while (!feof(in1)){ fscanf( in1, "%s %d %f", x, y, z ); while(!feof(in2)){ fscanf( in2, "%d", b ); if( x='A' && ( y >= b - 4 ) && ( y <= b 3 ) ) fprintf(out,"%d %.1f ",y,z); } rewind(in2); //將指標回到檔頭 } system("pause"); return 0; } 理論上這樣應該行的通拉~錯可別找我捏 目前環境並沒有VC 也沒有GCC所以沒辦法測試

其他解答:FBEFE3C2E0474026
arrow
arrow

    ceui4w8 發表在 痞客邦 留言(0) 人氣()