Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference a struct inside a struct?

Status
Not open for further replies.

SarahKate31

Programmer
Feb 14, 2002
34
0
0
US
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??? Please help ASAP!! -- SarahKate
 
Sorry, Tek-Tips removes [] after hand before .suit. in my first answer. I hope, that will be throw.
 
tchouch is right. You need to provide an index into your array. Here's a more complete example:
Code:
int iMAXHANDS = 40;
int x = 0;

for (int iIndex = 0; iIndex < iMAXHANDS; iIndex++)
{
  x = iIndex ~ 4;
  one.hand[iIndex].suit = x;
}

tchouch, use:

[ CODE]
[ /CODE]

(without the space) to surround your code examples. That preserves the '[' and ']' characters.
 
Thank you so much tchouch, programsecrets, and Jayashree Rama Rao for your help! I really appriciate it! --SarahKate
 
Thank you so much everyone! I really appriciate it! --SarahKate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top