Skip to main content
GameDev.net gamedev.net
🔒 Locked

integer arrays help!

Started by Maxfreilich Jan 3, 2004 at 12:44 PM 3 replies 450+ views
Original Post
Maxfreilich
Maxfreilich
Ok, I have 2 integer arrays, knum and enumb. enumb has more members than knum. so for example: enumb={25, 7, 14, 19, 3, 10}; knumb={13, 21, 5}; My question is, how do I go about making knumb just as long as enumb, by copying knumb over so it would be like: knumb = {13, 21, 5, 13, 21, 5); I know what the problem is, I just don't know how to code it. Thanks for your time. PS. I would have used my username but I am having some trouble using it again. Edit: Got my username, and this is in C++ btw. [edited by - Maxfreilich on January 3, 2004 1:47:35 PM]
tHiSiSbOb
tHiSiSbOb
Are you familiar with pointers? If not, I would read up on them because it is easy to do what you are trying to do with pointers. Look up "dynamic memory allocation".
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Grofit
Grofit
The other guys right you would HAVE to use pointers to use dynamic memory to make your array change sizes...but you would have to do something like this:

int Get_Enumb_Size() // or whatevers the biggest one
{
int x;

while(Enumb[x]!=NULL)
{
x++
}
return x;
}

then you would do something like

void main()
{
int *knum;

knum = new int[Get_Enumb_Size];
// then make a function to fill the new array
}

DONT FORGET TO USE: delete[] knum; when your done though if your going to do it multiple times

[edited by - Grofit on January 3, 2004 2:10:31 PM]
invective
invective
You could also just use the modulus operator to return the correct index for the knumb array.

knumb[index%knumb_length]
Maxfreilich
Maxfreilich
Thanks a lot for your replies, however I actually figured out how to do it without using pointers and dynamic memory location. Thanks for all of your help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.