Comment
Author: Admin | 2025-04-28
After researching I do believe I understand what the "Segmentation fault" error is. However, even after commenting out the code line by line, I can not seem to find where the fault is occurring in order to fix it. Is there something I am overlooking that is causing this error? Below is what shows up when I run the code:Ready to play (y/n)? y3C AH 4C 3H 4H 2H 5H 2C 5C ACHere's your cards: 3C AH 4C 3H 4HSegmentation fault (core dumped)Pasted below is the code that I am referring to. The commented out parts were just me trying to find where the error was occurring:#include #include #include #include #include #include #include #include #include using namespace std;vector bigDeck;vector cardDeck;vector playerHand;vector computerhand;vector shortvec;const int DEAL_CARDS = 5;void ResetDeck();void Shuffle();void DealACard();void DealQCard();void DealBCard();string CStr(int);int letsee2;int main(){cout > yn;if (yn == 'n' || yn != 'y') return 0;ResetDeck();srand(time(0));Shuffle();for (int f=0; f (atoi(computerhand[woh].c_str()))) { cout computerhand.size()) shortvec = computerhand;else shortvec = playerHand;cout asked Apr 28, 2013 at 23:25 You have a std::vector called bigDeck and in DealQCard you attempt to access its 0th element, despite the fact it has no elements. Did you mean to put some cards in bigDeck? answered Apr 28, 2013 at 23:31 Joseph MansfieldJoseph Mansfield111k22 gold badges247 silver badges328 bronze badges 1 Trying to access non-existent memory or memory which is being used by other process also causes the Segmentation Fault (core dumped).Core dumped means that the program state has been recorded, i.e, its resources that were in memory and processor. answered Dec 10, 2013 at 22:22 Sohail xIN3NSohail xIN3N3,0412 gold badges32 silver badges29 bronze badges
Add Comment