Changing size of array of pointers

This is a discussion on Changing size of array of pointers within the C Programming forums, part of the General Programming Boards category; Well I have a list of characters strings stored with pointers in this array: Code: char *list[20]; I never like ...

  1. #1
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398

    Changing size of array of pointers

    Well I have a list of characters strings stored with pointers in this array:
    Code:
    char *list[20];
    I never like hard coding numbers because of the way things can dynamically change. Is there a way to change the array size every time I find a new element to add? Probably something along the lines of realloc but I am not entirely sure.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Use dynamic memory allocation with malloc(), realloc() and free() from <stdlib.h>
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers trouble
    By saahmed in forum C Programming
    Replies: 39
    Last Post: 03-24-2006, 03:08 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  3. Replies: 11
    Last Post: 03-25-2003, 04:13 PM
  4. Class member array size with constuctor initalizer
    By rafe in forum C++ Programming
    Replies: 2
    Last Post: 10-14-2002, 10:09 AM
  5. Array of pointers help
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 02-14-2002, 11:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21