Hi,
I need to have an array so as to look like the following:
ArrayElement[1] = "First ELement";
ArrayElement[2] = "Second Element";
etc...
How do I declare this?
ie Is it
char* ArrayElement[3];
Or how is it declared?
Thanks in advance,
Jenny
Printable View
Hi,
I need to have an array so as to look like the following:
ArrayElement[1] = "First ELement";
ArrayElement[2] = "Second Element";
etc...
How do I declare this?
ie Is it
char* ArrayElement[3];
Or how is it declared?
Thanks in advance,
Jenny
To declare an array of strings, allocate the space for the largest string:Code:char ArrayElement[3][15];
strcpy(ArrayElement[0], "First ELement");
strcpy(ArrayElement[1], "Second Element"); // 14 chars + '\0'
strcpy(ArrayElement[2], "Last Element");
What are you trying to do?
-----
char *pArray = new char[SIZE];
-----
Is that what you want to do?
Kuphryn
Hi Guys!
Thanks for the answers
Alexey, It was exactly what I needed, Thanks!
;)
You could also use
Then there is no need to figure out how many you have or the size of the largest string.Code:const char* pArray[] =
{
"First Element",
"Second Element",
"Third Element"
};
Just because it should be said:
An array of std::string would be better.
A std::vector of std::string would be even better.
Jeff
Well said, that man! :)