
HELP: Dynamically Alloc'd array
"I need to dynamically allocate a one dimensional array of
near pointers. Can this be done? If so, any pointers? or
another approach?"
Array of 12 pointers to int, and one of 15 pointers to strings
(char arrays). If in tiny, small or medium models, they will
be near.
int **intPtrs = malloc(12 * sizeof(*intPtrs));
char **charPtrs;
if (!intPtrs)
puts("intPtrs allocation failed");
if ((charPtrs = malloc(15 * sizeof(*charPtrs))) == NULL)
puts("charPtrs allocation failed");
If compiling as C++, you'd need a cast on the call to malloc()
as in intPtrs = (int **) malloc(12 * sizeof(*intPtrs));
Ed