Computing.Net > Forums > Programming > How to delete record in an array??

How to delete record in an array??

Reply to Message Icon

Original Message
Name: ahpaul
Date: October 24, 2001 at 15:42:21 Pacific
Subject: How to delete record in an array??
Comment:

as the example below:

#include

main()
{
struct array1
{
char name[30];
}details[10];
}

ok, now there got 10 arrays, what if i entered all the array (10 names), and i need to delete any of it, then how?


Report Offensive Message For Removal


Response Number 1
Name: Mik
Date: October 24, 2001 at 23:51:03 Pacific
Reply: (edit)

Well that's why arrays aren't always used because you run into those kind of problems.
But if you have 10 elements in the array and you want to delete the 5th element. Then you will have to move the 6th to the 5th, the 7th to the 6th, etc.... And if you want to add an element in the array you will first have to move the rest over one place to make room for the new element. In your example each element in the array is only 30 bytes and there are only ten of those records so shifting those back and forth won't be that much of a drain. But if your records start getting larger you might want to look into Linked Lists.

Mik


Report Offensive Follow Up For Removal

Response Number 2
Name: ahpaul
Date: October 25, 2001 at 02:29:29 Pacific
Reply: (edit)

ok, I understand it! thanks!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: How to delete record in an array??

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge