Advertisement

Array of Strings

Started by March 20, 2003 11:01 AM
2 comments, last by Silly_con 21 years, 8 months ago
I have a problem reserving dynamic memory in C++ to a array of strings, I want to make a array of char* pointers and I have made this: char *ptr_array; ptr_array = new char[10]; // 10 pointers char* ? ptr_array[0] = (char *)new char[CAD_LEN]; // every pointer point to a CAD_LEN char* ? I''m too much confused
basically, I wan to reserve memory first for the array of pointers to strings, and later for every string in the array.
Advertisement
You are confused between the char pointers and char arrays... I''m not an expert in C++, but what I think you want to do is this:

//In order to make an array of strings, you have to declare a pointer to a char pointer
char **ptr_array;

//You initialize then the array of strings...
ptr_array = new *char[10];

//And finally you initialize each string...
ptr_array[0] = new char[10];

Correct me if I''m wrong...

Mac for productivity
Linux for development
Palm for mobility
Windows... for the Solitaire
Ciro Durán :: My site :: gamedev.net :: AGS Forums
thanks very much cyrax256, only you have a bit error in ptr_array = new *char[10]; that is ptr_array = new char* [10];

This topic is closed to new replies.

Advertisement