2d char array

Hello, could some show me some basic code of a 2d char array which is dynamic in size, that does not use char** but can only use a char pointer (char*). the number of rows is dynamic, however the size of each char array is 1024 long. Thank you :)
Hi,

Just use a std::vector<std::string>

std::string has a c_str function if you really need a char array - maybe you don't :+)

STL containers are created on the stack, but they have an internal pointer to the data which is on the heap, so you might not have to worry about dynamic memory.

http://www.cplusplus.com/reference/vector/vector/
http://www.cplusplus.com/reference/string/string/
First you need to create an array of strings.

char arrayOfWords[NUMBER_OF_WORDS][MAX_SIZE_OF_WORD];
Then, you need to enter the string into the array

int i;
for (i=0; i<NUMBER_OF_WORDS; i++) {
scanf ("%s" , arrayOfWords[i]);
}
Finally in oreder to print them use

for (i=0; i<NUMBER_OF_WORDS; i++) {
printf ("%s" , arrayOfWords[i]);
}

http://www.traininginsholinganallur.in/java-training-in-chennai.html# | http://www.traininginsholinganallur.in/android-training-in-chennai.html# | http://www.traininginsholinganallur.in/oracle-dba-training-in-chennai.html | http://www.traininginsholinganallur.in/python-training-in-chennai.html
Topic archived. No new replies allowed.