Hello stackoverflow so my question is: I want to make a function to generate the array of structures but i get an error whenever i finish inserting the values what is the problem? like so
struct INFO
{
char name[20]; // creating the strucure
int age;
};
void generateArr(INFO *p); // a function to generate the array
void readArr(INFO *p); // a function to read the array
int main()
{
INFO *ptr =new INFO; // a pointer that points to the structure
generateArr(ptr); // calling the functions
readArr(ptr);
delete[]ptr; // deallocating memory
}
void generateArr(INFO *p)
{
p = new INFO [3]; // generating three INFO structures
}
void readArr(INFO *p)
{
for (int i = 0; i < 3; i++)
{
cin >> p[i].name>> p[i].age; // inputting the elements
cout << endl;
}
}
I tried to make the code as clear as possible, ask me if anything is ambiguous.