Thread: Changing size of array of pointers

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

    Changing size of array of pointers

    Well I have a list of characters strings stored with pointers in this array:
    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
    Use dynamic memory allocation with malloc(), realloc() and free() from <stdlib.h>
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 04:08 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. Replies: 11
    Last Post: 03-25-2003, 05: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, 12:37 PM