accessing members in nested structs

This is a discussion on accessing members in nested structs within the C Programming forums, part of the General Programming Boards category; ok, I have these structures: Code: typedef struct card { char face; char suite; int value; int num; } CARD; ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    9

    Question accessing members in nested structs

    ok, I have these structures:

    Code:
    typedef struct card {
      
      char face;
      char suite;
      int value;
      int num;
    
    } CARD;
    
    
    
    typedef struct deck {
      
      CARD cards[MAX_CARDS];
      
      /* used cards */
      int struck[MAX_CARDS];
      
    } DECK;
    I'm trying to pass a pointer to a deck to a function which will initialize it, but whenever I try to access members (e.g. d->cards[k].num) it gives me a segmentation fault error.

    any advice is greatly appreciated.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    Have you actually initialized d or is it just pointing to some random memory location?
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    oops... thanx!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dynamicly adding data members to structs
    By ITAmember in forum C Programming
    Replies: 11
    Last Post: 06-01-2009, 03:26 PM
  2. accessing enum members
    By stanlvw in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2008, 02:58 PM
  3. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  4. accessing array of structs values
    By WaterNut in forum C++ Programming
    Replies: 12
    Last Post: 07-08-2004, 08:47 PM
  5. Accessing private data members
    By maloy in forum C++ Programming
    Replies: 11
    Last Post: 10-04-2002, 02:48 PM

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