Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:15:10+00:00 2026-06-18T03:15:10+00:00

So basically I have an array of Card objects initialized like so… Card *pile[MAX];

  • 0

So basically I have an array of Card objects initialized like so…

Card *pile[MAX];

where MAX is 52. This array is a member of a class called CardPile

The problem I’m having occurs when I try to fill an instance of CardPilecalled drawPile to its 52-element capacity by using a for-loop…
This is how I chose to do that:

char faces[] = "A23456789TJQK";
char suits[] = "SHDC";
int k = 0;
for(int i=0; i<13; i++){
    for(int j=0; j<4; j++){
        drawPile.add(new Card(faces[i], suits[j]));
        //the line below is displayed on the console for debugging purposes
        cout << drawPile.pile[k]->face << drawPile.pile[k]->suit <<  ", pile size=" << drawPile.size << endl;
        k++;
    }
}

and here is the code for the .add(Card*) method…

void CardPile::add(Card *c){
    for(int i=0; i<52;i++){
        if(pile[i]){
            continue;
        } else {
            this->pile[i]=c;
            size++;
            break;
        }
    }
}

…and when I run the program, I get this displayed in the console…

AS, pile size=1
AH, pile size=2
AD, pile size=3
AC, pile size=4
2S, pile size=5
2H, pile size=6
2D, pile size=7
2C, pile size=8
3S, pile size=9
3H, pile size=10
3D, pile size=11
3C, pile size=12
4S, pile size=13
4H, pile size=14
4D, pile size=15
4C, pile size=16
5S, pile size=17
5H, pile size=18
5D, pile size=19
5C, pile size=20
6S, pile size=21
6H, pile size=22
6D, pile size=23
6C, pile size=24
7S, pile size=25
7H, pile size=26
7D, pile size=27
7C, pile size=28
8S, pile size=29
8H, pile size=30
8D, pile size=31
8C, pile size=32
9S, pile size=33
9H, pile size=34
9D, pile size=35
9C, pile size=36
TS, pile size=37
TH, pile size=38
TD, pile size=39

After that last line of output, the program stops running… My question is, why does the program stop after the 39th call to add() instead of finishing and filling the array to its allocated capacity?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:15:11+00:00Added an answer on June 18, 2026 at 3:15 am

    You need to initialize piles element, it default has random value:

    Card *pile[52] = {};
    

    Also you could try to use std::vector instead of array with raw pointer

    std::vector<Card> cards;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have an array like this: val base_length = Array( 0, 1, 2,
I have a pretty simple problem. Basically I have an array called $list that
Basically I have this string $str=word1 word2 word3; I need array( 'word1', 'word2', 'word3'
Basically I have a class method that returns a float array . If I
This is part of a larger project. Basically I have a class X to
Say I have an array that looks like this: array(100) { [0]=> array(4) {
Background I basically have an array, this array has the following format Array (
So basically I have an array of objects with properties. Now the array is
I am learning about arrays, and basically I have an array that collects a
So basically I have a huge array of arrays (only a 2-d array)... My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.