Randomizing dealing program C

This is a discussion on Randomizing dealing program C within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <time.h> struct card { char *face; char *suit; }; typedef struct card Card; void ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    93

    Randomizing dealing program C

    Code:
    #include <stdio.h>
    
    #include <stdlib.h>
    
    #include <time.h>
    
    struct card {
                    char *face;
                    char *suit;
            };  
    
    typedef struct card Card;
    
    void FillDeck ( Card *FDeck, char * face [  ], char * suit [  ] );
    
    void Shuffle ( Card *FDeck );
    
    void Deal ( Card *FDeck );
    
    
    int main( void )
    {
    
    Card Deck [ 52 ];
    
    srand( time (NULL) );
    
    char *face [  ] = { "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace" };
    
    char *suit [  ] = { "Diamonds", "Hearts", "Spaces", "Clubs" };
    
    FillDeck( Deck, face, suit );
    Shuffle( Deck );
    Deal( Deck );
    
    return 0;  
    void FillDeck ( Card * FDeck, char *face [  ], char * suit [  ] )
    {
            int i;
            for ( i = 0; i <= 51; i++ ) {
            FDeck [ i ].face = FDeck [ i % 13 ];
            FDeck [ i ].suit = FDeck [i/ 13 ];        }
    }
    
    void Shuffle ( Card *FDeck )
    {
    int i;
    int temp;
    int j;
    
            for ( i = 0; i <= 51; i++ ) {
            j = rand() % 52;
            temp = FDeck[ i ];
            FDeck[ i ] = FDeck[ j ];
            FDeck[ j ] = temp;        }
    }
    
    void Deal ( Card * FDeck )
    {
    int i;
            for ( i = 0; i <= 51; i++ ) {
            printf("%s of %s", FDeck[i].face, FDeck[i].suit);
            printf("\n");
            }
    }
    :44: error: incompatible types in assignment
    card4.c:45: error: incompatible types in assignment
    card4.c: In function ‚Shuffle‚:
    card4.c:57: error: incompatible types in assignment
    card4.c:59: error: incompatible types in assignment

    It is giving me the errors in bold and I don't get why? Can anyone help me out?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    FDeck [ i ].face = FDeck [ i &#37; 13 ];
    Portion marked in red is on one side but not the other...

    Code:
    int temp;
    int j;
    
            for ( i = 0; i <= 51; i++ ) {
            j = rand() % 52;
            temp = FDeck[ i ];
            FDeck[ i ] = FDeck[ j ];
            FDeck[ j ] = temp;        }
    }
    FDeck is not of type "int" is it?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Type mismatch. temp is of type int and FDeck is a pointer to an array of Card.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  4. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21