HELP: Dynamically Alloc'd array 
Author Message
 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?
Thanks.


Thu, 20 Nov 1997 03:00:00 GMT  
 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



Sun, 23 Nov 1997 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. non-local pointers to c(m)alloc'ed arrays

2. How access alloc'ed string as array?

3. can't delete my dynamically alloc'd array?

4. HELP: ways to alloc multidimensional arrays

5. dynamically increasing array's size

6. Dynamic Alloc - Arrays

7. global alloc and numeric arrays

8. (*)alloc for large arrays?

9. Help - Array of pointers to strings dynamically declared

10. Help: dynamically initialize char[][] array ...

11. HELP with returning dynamically allocated 2-D array in function

12. help sending 2d-arrays dynamically

 

 
Powered by phpBB® Forum Software