I need to create a nested structure in order to store some basic information about a person (name, age, address). So I created a structure called "information", and to store the address, I created another nested structure inside "info" called "address". But whenever I suggest storing values with a for loop, I get errors. What is the problem and how can I solve it?
[Error] 'struct Info' does not have a name named 'address'
Declaration [Warning] does not declare anything [enabled by default]
#include <stdio.h>
int main(){
struct Info{
char name[30];
int age;
struct address{
char area_name[39];
int house_no;
char district[39];
};
};
struct Info Person[10];
int i;
for(i=0;i<10;i++){
printf("enter info of person no %d\n",i);
printf("enter name\n");
scanf("%s",&Person[i].name);
printf("enter age\n");
scanf("%d",&Person[i].age);
printf("enter address :\n");
printf("enter area name :\n");
scanf("%s",&Person[i].address.area_name);
printf("enter house no : \n");
scanf("%d",&Person[i].address.house_no);
printf("enter district : \n");
scanf("%s",&Person[i].address.district);
}
}
source
share