Posted by James Durbin on 1999-11-03
or to better clerify:
char letters[11][10];
will make an array of 11 arrays of 10 chars each...
letters will point to letters[0] and
letters[n] will be a pointer to letters[n][0](n being any number between
0 and 10, just like in:
char letters2[10];
letters2 will point to letters2[0]...
.. if you want to have 11 dynamic strings you could have:
char *letters[11]; //an array of 11 pointers to chars
..
for(x=0;x<11;x++)
{
...
letters[x] = new char[Length_of_string];
}
or a dynamic number of dynamic strings:
char **letters; // a pointer to a pointer to a char
..
letters = new char*[Number_of_strings];
for(x=0;x<Number_of_strings;x++)
{
...
letters[x] = new char[Length_of_string];
}
> It is fairly easy to make an array of arrays as long as you keep all your
> values clear in your head when you assign them. Just use somethings like
> char letters[10][10];
> this would make an array of 10 arrays that each have a length of 10
> characters. WAs this what you were looking for at all? I have a tendency to
> misinterperate what people mean.
> >Sorry.. I know this question is very amateur, but how would I store a C++
> >string in an array of strings? Since a string is an array of characters,
> >basically my question is how to make an array of arrays. Or is there an
> >easier way to store multiple strings? Sorry again for the newbie question.
--
/*
From: James H. Durbin
Email: divine-bovine@xxxx.xxx
*/
Previous post | Next post | Timeline | Home