c++ Segmentation fault when taking int input from user in terminal but not xcode -
i having issues reading in file xcode decided switch terminal test it, in terminal getting segmentation fault when following function executes (only when choosing 1). ideas?
turns out problem reading file in. going post question handling that.
struct system { character player; }; struct character { string name; ushort money; ushort intelligence; ushort time; ushort steps; ushort score; }; bool get_number ( int& number ) { while ( !( cin >> number ) ) { if ( cin.eof() ) return false; else { char ch; cin.clear(); cout<<"invalid input, please try again: "; while (cin.get(ch) && ch != '\n' ); } } return true; } void viewmenu(menu menuchoice) { cout << menuchoice.options; cout << "\nplease choose option: "; int number; get_number(number); if (menuchoice.choice == 0) { if (number == 1) { struct system game; startgame(playername); } else if (number == 2) { viewscores(gamescoreboard); viewmenu(startmenu); } else { cout << "goodbye"; exit(0); } }
again, works fine in xcode, in terminal fails when choosing "1".
Comments
Post a Comment