# temporary arrays

Printable View

• 02-20-2002
phantom
temporary arrays
I have a temporary array that gets used when needed and then left for the next time it is needed. So how can I reset the whole array without going through the long way ->
long way
temp_array[0]=1;
temp_array[0]=2;
temp_array[0]=3;
temp_array[0]=4;
temp_array[0]=5;

I have tried ->
temp_array[]={0, 0, 0, 0, 0}; and
temp_array[5]={0, 0, 0, 0, 0};

James
• 02-20-2002
DavidP
try this:

//put this at top of code
#define ArraySize(x) ((sizeof(x)) / (sizeof(x[0])))

//declaration of array
int *myArray = new int[5];

...code...

//resetting of array
myArray = new int[ArraySize(myArray)];

Of course if you dont like pointers...you could always use a for loop:

int myArray[5];
for(int x = 0; x < 5; x++) myArray[x] = 0;
• 02-20-2002
Uraldor
memset(temp_array, 0, sizeof(temp_array));
• 02-21-2002
phantom
Code:

```int myArray[5]; for(int x = 0; x < 5; x++) myArray[x] = 0;```
That's a great idea for reseting all the values to 0, I will use it one day :) But what about if I wish to reset the values to say {1, 2, 32, 5, 7} e.t.c
• 02-21-2002
Fordy
Quote:

Originally posted by phantom
Code:

```int myArray[5]; for(int x = 0; x < 5; x++) myArray[x] = 0;```
That's a great idea for reseting all the values to 0, I will use it one day :) But what about if I wish to reset the values to say {1, 2, 32, 5, 7} e.t.c

Well I guess it would depend where you are getting the "1, 2, 32, 5, 7" from......is it part of an identifiable sequence? if so, perhaps you could recreate it......if not, then you would need to hard code the resetting process