You could do something like
person *firends = NULL;
if (inputPerson.numFriends) {
friends = malloc(inputPerson.numFriends * sizeof(*friends));
for (int i = 0; i < inputPerson.numFriends; i++) {
printf("Enter the person's first name: ");
gets(friends[i].firstName);
...
}
}
And use this firends
later
if (firends) {
...
}
Note: gets()
is quite dangerous, you should replace it with safer fgets()
.