Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I don't know what I'm doing wrong within my program but I'm getting a segmentation fault (core dumped) when compiling on vscode. Any clues

Hi,

I don't know what I'm doing wrong within my program but I'm getting a segmentation fault (core dumped) when compiling on vscode. Any clues would be appreciated, thank you.

here is what valgrind says:

Command: program4

==30478==

==30478== Invalid read of size 1

==30478== at 0x5692037: ____strtol_l_internal (strtol_l.c:293)

==30478== by 0x568E94F: atoi (atoi.c:27)

==30478== by 0x40567B: main (in /nfs/stak/users/a/programs/prog4/program4)

==30478== Address 0x0 is not stack'd, malloc'd or (recently) free'd

==30478==

==30478==

==30478== Process terminating with default action of signal 11 (SIGSEGV)

==30478== Access not within mapped region at address 0x0

==30478== at 0x5692037: ____strtol_l_internal (strtol_l.c:293)

==30478== by 0x568E94F: atoi (atoi.c:27)

==30478== by 0x40567B: main (in /nfs/stak/users/a/programs/prog4/program4)

==30478== If you believe this happened as a result of a stack

==30478== overflow in your program's main thread (unlikely but

==30478== possible), you can try to increase the size of the

==30478== main thread stack using the --main-stacksize= flag.

==30478== The main thread stack size used in this run was 8388608.

==30478==

==30478== HEAP SUMMARY:

==30478== in use at exit: 0 bytes in 0 blocks

==30478== total heap usage: 0 allocs, 0 frees, 0 bytes allocated

==30478==

==30478== All heap blocks were freed -- no leaks are possible

and here is the main() of the code c++:

#include "bats.h"

#include "event.h"

#include "gold.h"

#include "board.h"

#include "menu.h"

#include "pit.h"

#include "room.h"

#include "wumpus.h"

#include

//#include

#include

using namespace std;

int main(int argc, char** argv){

int size= atoi(argv[1]);

while(size < 4){

if(size < 4){

cout<<"That's too small please reinput size larger than 4"<

cin>>size;

}

else{

break;

}

}

// cout<< "enter size of cave:";

// cin >> size;

bool over = false;

int option, again=1, same;

Board Play(size);

Play.rand_events();

Play.start_event();

Play.print_map();

Play.event_check();

do{

while(!over){

cout<<"What to do in this cave?: "<

cout<<"1. Move around or 2. Shoot an arrow or 0. to quit game: ";

cin >>option;

if(option ==1){

if(Play.set_direction() == 1){

break;

}

}

else if(option == 2){

if(Play.arrow_move() == 1){

break;

}

}

else if(option == 0){

over = true;

again = 0;

break;

}

Play.print_map();

}

if(option == 0){

again = 0;

}

else{

cout << "Again? (1) or Stop (0): ";

cin >>again;

if(again == 1){

cout<<"Same board? (1) or differnt(0): ";

cin>> same;

if(same == 1){

Play.start_event();

Play.print_map();

}

else if(same == 0){

Play.rand_events();

Play.start_event();

Play.print_map();

}

}

}

}while (again == 1);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions