how build a dynamic array from a struture?
imagine that you have these struct:
Code:
struct Person
{
char Name[255];
int age;
};
and you create a variable array:
Person a[20];
but then you only need 3. how can i change it?
i try several things and read some info, but i only get errors:(
i understand that i'm using C code with some C++, but i don't know C++(for now).. after i finish C i will;)
these sample is for see if i can do something... i'm tired loking for something and nothing works:(
Re: how build a dynamic array from a struture?
There are many different types of containers in the standard library. Take a look at the vector class for instance (http://http://www.cplusplus.com/refe...vector/vector/)
Re: how build a dynamic array from a struture?
Quote:
Originally Posted by
Atheist
i did a mistake in link;)
sorry i read that before and i never understand that, maybe when i learn C++ i understand;)
and i resolve it:
1 - we must create a pointer variavel;
2 - we must point to NULL;
3 - now we do:
(the pointer name can be a subclass and then the struture)
PointerName = (vartype*) realloc (PointerName, NumberofIndices * sizeof(vartype));
the vartype can be a structure;)
4 - when we don't need the pointer we must free the mesmory:
free(PointerName);
5 - if your windows gives an error and close the program, then see if you have used another pointer without recreate it;)
thanks for all