I have to remove an element from index = 7 from an array and then move the rest of the elements to the positions 7, 8, 9, and so on.. i looked in my book but i cant find the remove code... does anyone know how i can remove the element and then move the rest?

thanks

Recommended Answers

All 2 Replies

array[7] = array[8];
array[8] = array[9];

And so on, but you'll probably want to use a loop.

there's another solution a bit more complicated than the one from salem (wich is pretty simple, nonetheless pretty accurate to your question), but i'd rather create a temporary array, transer the files from array1 into array2, delete array1, create (again) array1[size-1], and transfer again all information, but the element you wish to remove.

This is pretty useful when you use large arrays and you wish to print them or use them in other processes (with a loop) that could/will use the entire array... this way, you have the amount of elements you need in your array, and you donĀ“t have to worry about the last elements being the same...

This may also work when adding an element to the array, except that when you create the array again, the size must be [size+1], and then you read the information for the last element...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.