Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

how do you reset an array?

This topic is 4777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an array and i try declaring it again but that does not work. So how can I reset it back to the orginal values? [Edited by - kingpinzs on April 27, 2005 3:28:06 AM]

Share this post


Link to post
Share on other sites
Advertisement
I wasn't certain what you meant either.

I tend to initialize arrays to zero. So to me the phrase "reseting an array to it's original value" means resetting it to zero.

If the array is one dimensional, this can be done using the memset function directly or a loop can be used

const int length = 16;
int array[length];

memset(array, 0, length*sizeof(int));

for (int i = 0; i < length; i++) {
array = 0;
}

if the array was set to some other values

(just as an example)

for (int i = 0; i < length; i++) {
array = i;
}

you could make a copy of the array

int backup[length];

memcpy(backup,array,length*sizeof(int));

then to restore

for (int i = 0; i < length; i++) {
array = backup;
}

Does that help?

Share this post


Link to post
Share on other sites
Never mind I fixed it

I just redeclared each array value back to its orginal

thanks for the help

[Edited by - kingpinzs on April 27, 2005 5:57:27 PM]

Share this post


Link to post
Share on other sites
Also, if you mean to change the array size you could do like this:

int * array; // pointer to array
array = new int[10]; // array, size 10.
delete []array; // deallocating array from memory
array = new int[15]; // array, new size 15...
delete []array; // a good programmer always deallocate his/her stuff...

And so on...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What the hell are you talking about?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!