Nested structure in c
You declared a type struct address
in the structure Info
but not a data member of this type.
You can write for example
struct Info{
char name[30];
int age;
struct address{
char area_name[39];
int house_no;
char district[39];
} address;
^^^^^^^^
};
The structure Info
have a nested structure named address
, but not a member variable named address
.
You should do
struct Info
{
...
struct
{
...
} address;
};
What you have at the moment is just a declaration of a structure called address
, but you'll need a variable called address
in struct Info
to use the Person[i].address
syntax.
What you need is to move the word address
a bit:
struct Info{
char name[30];
int age;
struct {
char area_name[39];
int house_no;
char district[39];
} address; // <<< here it is now
};
Another option is to use the following:
struct Info{
char name[30];
int age;
struct addr{ // as noted by @JonathanLeffler,
// it's not necessary to change the
// name of a struct
char area_name[39];
int house_no;
char district[39];
};
struct addr address; // <<< a variable of type struct addr
};