c
1#define WORLD_H 38 2#define WORLD_W 38 3 4void fileop(char temp[WORLD_H ][WORLD_W]){ 5 6 FILE* fp; 7 char txt; 8 char fname[] = "sample_data2.txt"; 9 10 fp = fopen(fname, "r"); 11 if (fp == NULL) { 12 printf("%s file not open!\n", fname); 13 14 return -1; 15 16 } 17 18 for (int rread = 0; rread < WORLD_H; rread++) { 19 20 for(int cread = 0; cread < WORLD_W; cread++){ 21 22 txt = fgetc(fp); 23 24 if (txt == '\n') { break; } 25 26 else if (txt == '1'){ 27 28 temp[rread][cread] = 1; 29 } 30 else if (txt == '.') { 31 32 temp[rread][cread] = 0; 33 34 } 35 36 37 } 38 39 } 40 fclose(fp); 41 42} 43
sample_data2.txt
......................................
.........................1............
.......................1.1............
.............11......11............11.
............1...1....11............11.
.11........1.....1...11...............
.11........1...1.11....1.1............
...........1.....1.......1............
............1...1.....................
.............11.......................
......................................
......................................
......................................
sample_data2.txt を読み込んで 配列に格納したいのですが、上手くいきません。
アドバイス頂けると幸いです。
------------------追記------------------------------
関数はmain関数から下記のように呼び出してます。
fileop(map);
.のところは. で 1のところは@ で 表示したいですが
実行すると、 すべて. で表記されてしまっています。
回答2件
あなたの回答
tips
プレビュー