Our teacher gave this code and we need to get this code operational.
How can I print the values inside of array?
cout << wizardsCollection->birthYear;
is returns what I gave but wizardsCollection->nameSurname returns empty value.
Here's the rest of the code:
struct Wizard {
string nameSurname;
int birthYear;
string hairColour;
};
struct Wizard *createWizards() {
Wizard wizardsCollection[3];
for (int index = 0; index < *(&wizardsCollection + 1) - wizardsCollection; index = index + 1) {
wizardsCollection[index].nameSurname = "Name and surname of " + index;
wizardsCollection[index].birthYear = 0;
wizardsCollection[index].hairColour = "Hair colour of " + index;
}
return wizardsCollection;
}
int main()
{
Wizard *wizardsCollection = createWizards();
cout << wizardsCollection->nameSurname;
}