데이터 파일 (미로)을 읽으려고합니다. 그 중 일부는 나 자신이 seg fault로 코딩 한 것 같습니다. 나는 대학에서 강의를하기에 아팠다고 인정합니다. 동적 할당에 대해 이야기하고 내 문제를 철저히 조사했습니다.iostream 및 포인터를 사용하여 Seg 오류 가져 오기
다음void MazeClass::ReadMaze(ifstream& mazedata) {
mazedata >> row >> column; // Pulls the size from the file
GetExit(mazedata); // Does the same for above, just for the Exit (Required in Class)
GetEntrance(mazedata); // Does the same, just for the entrance (Required in Class)
maze = new char*[row]; // First array of pointers for 2d array
for (unsigned i; i<row;i++)
{ // Creates the second set of arrays
maze[i]=new char[column];
}
for (int y=0;y<column;y++)
{ // Keeping the maze inside boundries (step 1)
for (int x=0;x<row;x++) // (Step 2)
{
maze[x][y]=mazedata.get(); // <--- Here is where my Seg Fault happens.
}
}
}
은 GDB가 나에게 말한다 무엇 :
프로그램 신호 SIGSEGV, 분할 오류를받은 여기에 코드 내 조각이다. MazeClass.cpp의 MazeClass :: ReadMaze (this = 0xbffff524, mazedata = ...)에서 0x08048fe9 36 36 maze [x] [y] = mazedata.get();
도움을 주셔서 감사합니다. 보기 MyMaze2.dat의 존재 : 출력으로
(gdb) run
Starting program: /home/athetius/projects/code/netbeans/OLA4/a.out
Please Enter Data Filename: MyMaze2.dat
**************12142*********** ***12142*
* 12142***** * * 12142 *
* 12142 ************ 12142***
*** * 12142 ****12142****
* 12142 12142 *
* ****12142***** ** * 12142 *
* 12142 * 12142 * * *
* 12142 *******12142*** *
* 12142* ** ***12142*********
* 12142 12142
* 12142 *************12142*** *
* 12142 12142 ***** **
**12142************* 12142 * *
*12142 ******* 12142 **
12142***************12142
Program exited normally.
:
************************* ****
* ***** * * *
* ************ ***
*** * ********
* *
* ********* ** * *
* * * * *
* ********** *
* * ** ************
*
* **************** *
* ***** **
*************** * *
* ******* **
******************************
지금 내 코드가 바보 같은 실수로 고정되어, 이제 다음 문제로 이동할 수 있어요
하하하. 나는 그것을 간과했다, 지금 내가 펑키의 무엇인가 얻고 있지만. – Athetius
새로운 질문을 시작하면 더 많은 행운을 빕니다. 질문에 응답이 없으면 더 많은 사람들이 반응을 얻습니다. 실제로 미로를 인쇄하는 코드를 게시 할 수도 있습니다 ... 도움이 되었기 때문에 기쁩니다. – dappawit