Help! Array Question...
Hey,
I was just wondering how I could "delete" an entry in an array and have the entries after it move their index number down a place to take the place of the deleted entry. Example:
int array[3] = {1, 2, 3};
array[0] + 1 = x
In this example x would equal 2... but how could I change my array so that it would look like this:
delete_array entry 1
// now array looks like this
array[3] = {2, 3}
array[0] + 1 = x;
Now x would equal 3... but how can I do this? Please help! It is extremely important for me to implement this feature so I can finish my game! Thanks...
-Jesse
maybe you could use CArray from MFC if you use this
else what you have to do is a loop like that
for(i=delete_entry;i{
array=array[i+1];
}
and I dont think that you can do something like
array[0] + 1 = x;
it will give you an error...
cyberg
else what you have to do is a loop like that
for(i=delete_entry;i
array=array[i+1];
}
and I dont think that you can do something like
array[0] + 1 = x;
it will give you an error...
cyberg
cyberg- cyberg_coder@hotmail.com- http://members.xoom.com/cybergsoft
grrrrrrrr html tag!!!!
what I have to do to post my code correctly?
what I have to do to post my code correctly?
cyberg- cyberg_coder@hotmail.com- http://members.xoom.com/cybergsoft
August 03, 2001 12:56 AM
this shifts everything down 1.
you can play around with this theme to create a general array
element deletor.
int t[] = {1,2,3};
int s = sizeof(t)-sizeof(int);
memcpy( t, &t[1], s-1 );
you can play around with this theme to create a general array
element deletor.
int t[] = {1,2,3};
int s = sizeof(t)-sizeof(int);
memcpy( t, &t[1], s-1 );
webmunkey - The Anonymous Poster knows his stuff. memcpy is a good choice.
cyberg - To get the < and > characters on this board, you have to type < and > . It can seem annoying, but such is life when html is enabled.
Sandman - Webmunkey seems to only be learning the language. Give ''em a chance to understand the basics before doing anything more complicated. I know that linked lists aren''t really that hard, but they can seem complicated to a beginner.
cyberg - To get the < and > characters on this board, you have to type < and > . It can seem annoying, but such is life when html is enabled.
Sandman - Webmunkey seems to only be learning the language. Give ''em a chance to understand the basics before doing anything more complicated. I know that linked lists aren''t really that hard, but they can seem complicated to a beginner.
Actually, You can''t use memcpy in this situation. If you read in K&R, you''ll see you should use memmove when memory overlaps each other. You''ll see location &t[1] is a part of t, so you should use memmove. We had a problem here at work where someone was using memcpy and the source was part of the destination.
My Gamedev Journal: 2D Game Making, the Easy Way
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
I would highly reccomend Linked Lists, if you don''t know how to use them find a tutorial on them or get ahold of me.
Thanks everyone! I'm not familiar with linked lists yet, those will come later, but I did use the Anonymous Poster's algoritm and it worked great after I changed it to what BeerNutts said. Thanks again,
-Jesse
Edited by - webmunkey on August 3, 2001 12:08:20 PM
-Jesse
Edited by - webmunkey on August 3, 2001 12:08:20 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement