Thread: Coredump problem!

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    7

    Coredump problem!

    Hi my program is getting core dumps when trying to print out the 52 shuffled strings! Could someone take a peek and tell me what the problem could be? Thanks, much appreciated.

    #include<stdio.h>
    #include<stdlib.h>
    void shuffle_cards(char *deck[]);


    int main(void)

    { /*BeginMain*/

    char *deck[25];

    int i;
    int j;

    deck[0] = "Ace of Clubs";
    deck[1] = "Deuce of Clubs";
    deck[2] = "Three of Clubs";
    deck[3] = "Four of Clubs";
    deck[4] = "Five of Clubs";
    deck[5] = "Six of Clubs";
    deck[6] = "Seven of Clubs";
    deck[7] = "Eight of Clubs";
    deck[8] = "Nine of Clubs";
    deck[9] = "Ten of Clubs";
    deck[10] = "Jack of Clubs";
    deck[11] = "Queen of Clubs";
    deck[12] = "King of Clubs";
    deck[13] = "Ace of Diamonds";
    deck[14] = "Deuce of Diamonds";
    deck[15] = "Three of Diamonds";
    deck[16] = "Four of Diamonds";
    deck[17] = "Five of Diamonds";
    deck[18] = "Six of Diamonds";
    deck[19] = "Seven of Diamonds";
    deck[20] = "Eight of Diamonds";
    deck[21] = "Nine of Diamonds";
    deck[22] = "Ten of Diamonds";
    deck[23] = "Jack of Diamonds";
    deck[24] = "Queen of Diamonds";
    deck[25] = "King of Diamonds";
    deck[26] = "Ace of Hearts";
    deck[27] = "Deuce of Hearts";
    deck[28] = "Three of Hearts";
    deck[29] = "Four of Hearts";
    deck[30] = "Five of Hearts";
    deck[31] = "Six of Hearts";
    deck[32] = "Seven of Hearts";
    deck[33] = "Eight of Hearts";
    deck[34] = "Nine of Hearts";
    deck[35] = "Ten of Hearts";
    deck[36] = "Jack of Hearts";
    deck[37] = "Queen of Hearts";
    deck[38] = "King of Hearts";
    deck[39] = "Ace of Spades";
    deck[40] = "Deuce of Spades";
    deck[41] = "Three of Spades";
    deck[42] = "Four of Spades";
    deck[43] = "Five of Spades";
    deck[44] = "Six of Spades";
    deck[45] = "Seven of Spades";
    deck[46] = "Eight of Spades";
    deck[47] = "Nine of Spades";
    deck[48] = "Ten of Spades";
    deck[49] = "Jack of Spades";
    deck[50] = "Queen of Spades";
    deck[51] = "King of Spades";


    shuffle_cards(deck);
    printf("\n");
    for(i=0;i<52;i++)
    {
    printf("%s\n",deck[i]);
    }

    }/*EndMain*/

    void shuffle_cards ( char *deck[] )

    {/*Begin Shuffle*/
    int i;
    int r;
    char *temp;
    for(i=0; i < 52 ; ++i)
    {
    temp = deck[i];
    deck[i] = deck[r=( rand() % 52 )];
    deck[r] = temp;
    }

    }/*End Shuffle*/

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    int main(void)

    { /*BeginMain*/

    char *deck[25];

    int i;
    int j;

    deck[0] = "Ace of Clubs";
    deck[1] = "Deuce of Clubs";
    deck[2] = "Three of Clubs";
    deck[3] = "Four of Clubs";
    deck[4] = "Five of Clubs";
    This is a lousy way to do it, but THIS is your problem:

    char * deck[25]

    See? You made a TYPO! Try 52 instead of 25!

    Anyway, this is a better way to do this:
    Code:
    char * deck[52] =
    {
        "Ace of Clubs",
        "Deuce of Clubs",
        ...and so on...
    };
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM