Quote:
|
Originally Posted by bdjuf
got it! thanx guys
now another question, how do I reset an array? make it all empty again?
|
Assuming it's a contiguous area of memory and a simple array:
Code:
memset((void *)array_ptr, number_of_elements * sizeof(array_type), 0);
Alternately, you can request it be zeroed while allocating:
Code:
array_ptr = (array_type *)calloc(number_of_elements, sizeof(array_type));
You're doing c++, so you can always just destroy the old object and create a new one, which should set all values to their prototypes as well... if not, you can do the memset() thing in the object constructor.
HTH. HAND.
PS - If you malloc()'d the array originally, make sure you free() it before doing a new malloc(), otherwise you'll leak ram.
