[aclug-L] Re: Simple C question (which shows my C ignorance)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Thu, 03 Feb 2000, you wrote:
> On Thu, 3 Feb 2000, Larry Bottorff wrote:
>
> Let me simplify things, make sure I understand what's going on:
>
> > I do a malloc for each member of the array (of stuctures):
> > array1[count] = ... as I need it after declaring
> > array1[NUM] beforehand. Then I need to remove a given member of array1.
>
> > If I shift everything down, how do I use realloc?
>
> skip the realloc and just use a for() loop. Loop from the one you
> want deleted until NUM-1; assign [i] = [i+1]. Decrement NUM by 1.
Better yet, use a linked list instead of the array of pointers. Then you just
change the
previous/next pointers for the list elements before and after the one you're
deleting and free the memory for it. You don't have to resequence the entire
rest of your array to remove a pointer from the middle of it.
Greg
|
|