Originally Posted by
nevrax
Hi,
I'm pretty new with the notion of structure and I need some help. I would like to put, for example, the first name, last name, age and the phone number of a person in a structure like:
Code:
struct
{
char FirstName[16];
char LastName[16];
int age;
char PhoneNumber[10];
} person;
My problem is that I have multiple persons (20 for example). I would like to put them all in one array that would contain the 20 structures. Could someone show me an exemple how to do this when these info are read from the keyboard and, when they are read from a .txt file.
Thanks
Your problem is that this code defines an anonymous structure without an identifier and immediately initializes one "person". If you want to reuse the structure, you can write:
Code:
struct person {
char FirstName[16];
char LastName[16];
int age;
char PhoneNumber[10];
};
int main(void)
{
struct person myPerson1, myPerson2, myPersonArray[20];
}