#include <iostream>
#include <cstring>
int main(void)
{
/* Create the seed (note the last word's length is zero) */
constchar *line[] = {"Hello", "world. ", "Nice", "to", "meet", "you.", ""};
/* A char pointer pointer */
char **words = NULL;
/* Figure out how many words there are */
int amountOfWords = 0;
for (int pos = 0; strlen(line[pos]) > 0; pos++)
amountOfWords++;
/* Make words be an array of char pointers, the size of the amount of words */
words = newchar*[amountOfWords];
/* The pointers in the words array can be used like any other
* You simply have an array of them */
for (int i = 0; i < amountOfWords; i++)
{
words[i] = newchar[strlen(line[i]) + 1];
strcpy(words[i], line[i]);
}
/* Print 'em out */
for (int i = 0; i < amountOfWords; i++)
std::cout << words[i] << " ";
std::cout << '\n';
/* Clean up */
for (int i = 0; i < amountOfWords; i++)
delete [] words[i];
delete [] words;
return 0;
}
int fixedValue = 15;
int dynamicValue;
cin >> dynamicValue;
int **matrix;
matrix = newint*[fixedValue];
for(int i = 0; i < fixedValue; i++)
matrix[i] = newint[dynamicValue];
for(int r = 0; r < fixedValue; r++)
for(int c = 0; c < dynamicValue; c++)
m[r][c] = 0;
Makes a pointer array of pointers making it 2D, also initializes all values to 0.
line 7 creates the first 'fixed' array of size 15.
for loop on line 8 creates an array of 'dynamic size' in each of the first's array slots.
loop through row and column just like any other 2D array to initialize.
I know this works because I did it for my matrix header for a homework assignment.