using realloc()
From: John Hanley (jdhanley_at_telusplanet.net)
Date: 07/30/04
- Next message: rossum: "Re: dynamic array of ints"
- Previous message: William: "Re: job agreement restrictions"
- Next in thread: John Hanley: "Re: using realloc()"
- Reply: John Hanley: "Re: using realloc()"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: using realloc()"
- Maybe reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: using realloc()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Jul 2004 16:33:15 -0600
This is my first shot at ever using realloc and I think I've used it wrong
somehow.
I start out with int * elements = (int *) malloc(sizeof(int)),
then in my next function, I pass it 'elements' which I reallocate memory for
in order to add another element dynamically:
elements=(int *)realloc(elements, sizeof(int)*(j+1));
When debugging this in gdb, I notice that when j=2, and I realloc, my
address of 'elements' changes. But when j=1, it was fine.
Any ideas as to how I am using this incorrectly?
Thanks so much!
John
- Next message: rossum: "Re: dynamic array of ints"
- Previous message: William: "Re: job agreement restrictions"
- Next in thread: John Hanley: "Re: using realloc()"
- Reply: John Hanley: "Re: using realloc()"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: using realloc()"
- Maybe reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: using realloc()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]