How can I get to a struct inside a struct???


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How can I get to a struct inside a struct???

  1. #1
    SarahKate Guest

    How can I get to a struct inside a struct???


    Hello all...Quick (hopefully) question: I have these structs:
    struct CARDS
    {
    int tagNumber;
    int number;
    char face;
    char suit;
    int value;
    int sort;
    };
    struct PLAYER
    {
    char name [15];
    CARDS hand [15];
    int handValue;
    int handIndex;

    };

    CARDS deck [52];
    PLAYER one;

    I want to assign a value (x) into the tagNumber, number, face, suit, value,
    and sort variables from within a function. This syntax is wrong according
    to the compiler:
    one.hand.suit = x;
    What is the correct syntax??? Can anyone help me??? -- SarahKate


  2. #2
    Danny Kalev Guest

    Re: How can I get to a struct inside a struct???



    SarahKate wrote:
    >
    > Hello all...Quick (hopefully) question: I have these structs:
    > struct CARDS
    > {
    > int tagNumber;
    > int number;
    > char face;
    > char suit;
    > int value;
    > int sort;
    > };
    > struct PLAYER
    > {
    > char name [15];
    > CARDS hand [15];
    > int handValue;
    > int handIndex;
    >
    > };
    >
    > CARDS deck [52];
    > PLAYER one;
    >
    > I want to assign a value (x) into the tagNumber, number, face, suit, value,
    > and sort variables from within a function. This syntax is wrong according
    > to the compiler:
    > one.hand.suit = x;
    > What is the correct syntax??? Can anyone help me??? -- SarahKate


    try

    one.hand[0].suit = x;


    remember that hand is an array, not a single struct.

    Danny

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center