Thread: Help with poker program(involving structs) C

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    33

    Help with poker program(involving structs) C

    Code:
    How do i set my Card struct to seperate variables(card1,card2, card3, card4,card5) which only holds the on the card_num(the card number)
    
    
    
    typedef struct card
    {
    	int card_num;
    	int suit;
    	int face;
    } Card;
    
    
    I tried this:
    
    				
                                    card1 = hand1[1].card_num;
    				card2 = hand1[2].card_num;
    				card3 = hand1[3].card_num;
    				card4 = hand1[4].card_num;
    				card5 = hand1[5].card_num; 
    
    
    with this as the initiallizer:
    Card hand1[5] = {0,0,0,0,0};

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Code tags are for code only. You don't need (and shouldn't have them) around everything. Your problem is your initializer. You have an array of structs. That means you need one set of curly braces for the array initializer, and one for each struct in the array. You have to provide an initializer for each element in the array, but can use shorthand for the struct. This should do it:
    Code:
        Card hand1[5] = {{0}, {0}, {0}, {0}, {0}};

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poker Program
    By DenJansen in forum C Programming
    Replies: 1
    Last Post: 12-21-2010, 12:54 AM
  2. Help with Poker program
    By juggernot in forum C Programming
    Replies: 4
    Last Post: 06-03-2009, 08:11 PM
  3. Menu problem involving structs
    By NyHoK in forum C Programming
    Replies: 5
    Last Post: 03-31-2009, 10:00 AM
  4. Replies: 2
    Last Post: 03-13-2003, 09:40 AM
  5. Please Help w/ Messy Poker Program
    By ray in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2002, 08:59 PM