[ back to toc ]

using structures

Date: 2002/03/30 11:31

Q:
hello there!

i want to ask about using typedef struct and the
-> operator.i have this example from my study guide:
typedef struct
{
int day;
int month;
int day;
}DATE;

typedef struct _person
{
char name [30];
DATE birth;
struct _person *next;
}PERSON;

they explain that the -> operator can be used as follows rptr->name.my
question is how do i write the statement for DATE birth using the ->
operator?

A:
Your DATE definition is boguous, as it has 'day' two times. You may want
to have 'year' instead.

To use the -> operator you need a pointer to the struct, thus all you need
is

PERSON *rptr;

and then you can use rptr->birth.month for example.

Regards,
Peter

Happy Easter

[ back to toc ]