|
From: Ioannis V. <iv...@em...> - 2003-03-31 01:15:46
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Khalid El-Kary > Sent: Monday, March 31, 2003 3:05 AM > To: Dev...@li... > Subject: [Dev-C++] array of strings > > > Hi fellows, > I'm developing a low-level C-based string manipulation API ... > in my Implementation of the function "explode" which splits a > string into > pieces (with a specified separator) and returns these pieces > into an array. > > The problem is, i need to initialize the returning array i > knew the way to > initialize the string array is: > > char *temp[5]; //where 5 is the number of array elements > > but ... for performance reasons, I need the number of > elements (5 above) not > to be specified from the begining, i mean i need to use > something like > realloc to resize this array on-the-fly ... > > Is there a possible way to do that fellows ? > > Thanx in advance :) You will have to use malloc(), calloc() and realloc() to allocate space on the free store. C99 provides the notion of variable length arrays which are built in arrays whose size can be defined at runtime (but cannot be changed during their lifetime). Dev-C++ (MINGW) supports C99 with the option -std=c99. Example of VLA: int size=7; int myvla[size]; and void whatever(int myvla[*]); Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |