• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [OT] An array of C-Strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] An array of C-Strings


  • Subject: Re: [OT] An array of C-Strings
  • From: email@hidden
  • Date: Sun, 27 Jan 2002 00:02:14 -0500

On Saturday, January 26, 2002, at 11:37 PM, Sam Goldman wrote:

I know that, but if you read carefully I said that in the actual use I don't
know how many 'word's there are and instead of putting a really big number
into days, I want to have it get bigger every time an entry is put into it.

Well, you asked why your sample was crashing - and that was the reason.

But your problem is still a memory thing, not a C++ thing - you want something like:

# include <stdlib.h>

#define CHUNKSIZE 10
main ()
{
int nchunks = 1;
char **days = (char **) malloc (CHUNKSIZE * sizeof (char *));

for (int i = 0; i < UnknownLargeNumber (); ++i) {
if (i == nchunks * CHUNKSIZE) {
++i;
days = (char **) realloc (days, CHUNKSIZE * sizeof (char *));
}
days [i] = newRandomLengthString ();
}
}

This would solve your problem as stated, but if your primary interest is in C++ and OOP, then you'll want to have a look at the collections available in the Standard Template Library.

Enjoy,

email@hidden


References: 
 >Re: [OT] An array of C-Strings (From: Sam Goldman <email@hidden>)

  • Prev by Date: Re: Daemons!
  • Next by Date: Re: [OT] An array of C-Strings
  • Previous by thread: Re: [OT] An array of C-Strings
  • Next by thread: Re: [OT] An array of C-Strings
  • Index(es):
    • Date
    • Thread