Leon Breedt wrote:
> i'm currently using a dynamically resized array to store a list of structs.
> its working nicely, what i want to know is this:
>
> are there any things i should be careful for, when using a pointer to an
> array?
You can't resize an array in-place, so whenever you resize it, its
address may change. If you have copied the pointer, you have to update
all of the copies when you resize the array.
This may seem obvious, but it's easy to overlook.
> it seems much easier to me to use an array that i resize dynamically,
> than use a linked list (i.e. sorting). and what is the best way to delete
> an item in the array that is, say, in the middle.
There are two alternatives. If you need to preserve the ordering, then
you have to memmove() the remainder of the array down one slot. If you
don't need to preserve the ordering, you can copy the last element
over the deleted element, and decrement the count.
> here are the pertinent declarations:
>
> #define GROW_BY 5
>
> int ListCount = 0;
> int ListSize = GROW_BY;
> pwlistentry (*PasswordList)[GROW_BY] = NULL;
>
> then, when i add entries, i check to see if ListCount+1 > ListSize, if
> so, i call realloc() to resize the array (PasswordList), and make it
> GROW_BY entries bigger, then i add the entry into the array.
>
> anything wrong with this approach?
Shouldn't the declaration just be
pwlistentry *PasswordList = NULL;
--
Glynn Clements <[EMAIL PROTECTED]>