If you have an array can you allocate it to a certain amount then if the user fills up the array can you use malloc to adjust the array to add more elements if needed? Thanks for any replies.
-CDuddley
Printable View
If you have an array can you allocate it to a certain amount then if the user fills up the array can you use malloc to adjust the array to add more elements if needed? Thanks for any replies.
-CDuddley
Yes, in fact, there's a function similar to malloc that does just that. Look up the function realloc(). It's one of the three allocation functions in C.
-Prelude
Thanks a bunch man :)...
-CDuddley
Anytime :)
I would have detailed it in my post, but my copy of K&R isn't on me as it should be and I don't remember the exact definition.
-Prelude
fyi!
you need to include stdlib.h
and the ptype is
void *realloc(void *ptr, size_t size);
change the size of mem pointed to by ptr
there will be no effect if there is not enough availabe memory
hth