User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,025 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,415 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 690 | Replies: 2
Reply
Join Date: Apr 2007
Posts: 4
Reputation: lionburn50 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
lionburn50 lionburn50 is offline Offline
Newbie Poster

Help removing an element...

  #1  
Apr 25th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,393
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 21
Solved Threads: 385
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: removing an element...

  #2  
Apr 26th, 2007
array[7] = array[8];
array[8] = array[9];

And so on, but you'll probably want to use a loop.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Mar 2007
Location: Honduras
Posts: 1,401
Reputation: Nichito is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 25
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: removing an element...

  #3  
Apr 27th, 2007
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[size] into array2[size], delete array1[size], 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...
Last edited by Nichito : Apr 27th, 2007 at 12:58 am.
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 10:12 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC