Assuming that I have a program that has an array of unknown lenght that consists of Customer
s.
Here, a customer struct:
struct Customer
{
char* lastname;
char* firstname;
int money;
};
And here - an array:
Customer* CustomerDB;
Okay. But the thing is that I want to add and remove customers dynamically during runtime. I don't want to allocate like 100 customers during declaration or during runtime - I want to allocate one at a time when it is needed.
Think of a simple AddCustomer function that allocates memory, enters the given data and then increments a counter (which is probably needed for iteration).
This is my main problem.
What I want is the array to behave exactly like one that has been declared with 100 arrays instead of a dynamical one.
The customer program above is just an example, please don't tell me that it's a bad idea to do that and that or that.
How do I create an
AddCustomer
function working for the code above?It is necessary that I can iterate through
CustomerDB