Array of Strings
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.
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
//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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement