現在、ファイルを2次元配列に1桁ずつ読み込もうとしています。データを取得しているファイルは、maze.txtです(コードの下に示されています)。現在の状態のプログラムはコンパイルされますが、プログラムが実行されると何も印刷されず永遠に実行されます。私はエラーが最初のforループに関連付けられていると仮定しています。ファイルを読み込み、配列に入力しようとしています
This is the output of Chris's solution
//Input: A txt file containing a 10 x 10 maze of 0s and 1s
//Output: A route from the top left to the bottom right passing through only 0s
#include <fstream>
#include <iostream>
using namespace std;
const int LENGTH = 10;
const int WIDTH = 10;
int main()
{ char mazeArray[LENGTH][WIDTH];
int counter = 0;
fstream mazeFile;
mazeFile.open("maze.txt");
if(mazeFile.fail())
{
cout << "File not found." << endl;
return 0;
}
do
{
cin >> mazeArray[counter];
counter++;
} while(mazeFile.good() && counter < LENGTH * WIDTH);
for(int j = 0; j > 100; j++)
{
cout << mazeArray[j] << endl;
}
return 0;
}
Maze.txt
0 1 0 0 1 0 0 1 0 0
0 0 1 1 1 0 0 0 0 1
1 0 1 0 1 0 1 0 1 0
0 0 0 0 1 0 1 0 1 0
0 0 0 1 0 0 1 0 1 0
1 1 0 0 0 0 1 0 1 0
1 1 1 1 1 0 0 0 1 0
0 0 0 0 0 1 0 0 0 0
1 1 1 1 1 1 0 1 0 0
0 0 0 0 0 0 0 1 1 0
'のための(int型J = 0; j>は100あり、j ++)'このループはゼロ回実行されます。たぶん、あなたが '(int j = 0; j <100; j ++)'を意味するのでしょうか – user463035818
ここでデバッガを使う方法を学ぶなら、ここでコピー/貼り付け/書式設定できるよりも素早くこのようなことを理解する方法を学びますその過程でいくつかのことを学びます。 –
あなたが元々求めていた問題を解決するために質問を編集しないでください。これは、将来の読書には役に立たず、既に回答を無効にしています。 – user463035818