DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links