array of char array in headerfile (string list) - some questions

S

sigi

i've got something like this in a headerfile:

const char* const StringList[]=
{
"FirstString",
"SecondString",
....
}

(haven't checked the syntax yet, but i guess it's ok?)

there can be more than one such list, later on i decide which to take and
use this to fill a std::map (i also got some defines to make code easier to
read... )

my questions:

is there any way to get number of strings in this list? if they were fixed
length there's the trick using sizeof var / sizeof var[0].

it would be easy to provide a const of values in this list, or having a
special "stop string" - just out of curiosity...

but i guess if there's something i would rather be compiler specific and
therefor this question won't belong here:)
 
B

benben

sigi said:
i've got something like this in a headerfile:

const char* const StringList[]=
{
"FirstString",
"SecondString",
....
}

(haven't checked the syntax yet, but i guess it's ok?)

there can be more than one such list, later on i decide which to take and
use this to fill a std::map (i also got some defines to make code easier to
read... )

my questions:

is there any way to get number of strings in this list? if they were fixed
length there's the trick using sizeof var / sizeof var[0].

This is indeed the answer.
it would be easy to provide a const of values in this list, or having a
special "stop string" - just out of curiosity...

If this is a question, the answer is, it doesn't matter, up to you.
 
R

Rolf Magnus

sigi said:
i've got something like this in a headerfile:

const char* const StringList[]=
{
"FirstString",
"SecondString",
....
}

(haven't checked the syntax yet, but i guess it's ok?)

there can be more than one such list, later on i decide which to take and
use this to fill a std::map (i also got some defines to make code easier
to read... )

my questions:

is there any way to get number of strings in this list? if they were fixed
length there's the trick using sizeof var / sizeof var[0].

The elements of an array are always fixed length. So this is indeed the way
to find the number of elements.
 
S

sigi

a my lord, for sure...

thanks.

Rolf Magnus said:
sigi said:
i've got something like this in a headerfile:

const char* const StringList[]=
{
"FirstString",
"SecondString",
....
}

(haven't checked the syntax yet, but i guess it's ok?)

there can be more than one such list, later on i decide which to take and
use this to fill a std::map (i also got some defines to make code easier
to read... )

my questions:

is there any way to get number of strings in this list? if they were
fixed
length there's the trick using sizeof var / sizeof var[0].

The elements of an array are always fixed length. So this is indeed the
way
to find the number of elements.
 
S

sigi

benben said:
sigi said:
i've got something like this in a headerfile:

const char* const StringList[]=
{
"FirstString",
"SecondString",
....
}

(haven't checked the syntax yet, but i guess it's ok?)

there can be more than one such list, later on i decide which to take and
use this to fill a std::map (i also got some defines to make code easier to
read... )

my questions:

is there any way to get number of strings in this list? if they were
fixed
length there's the trick using sizeof var / sizeof var[0].

This is indeed the answer.
it would be easy to provide a const of values in this list, or having a
special "stop string" - just out of curiosity...

If this is a question, the answer is, it doesn't matter, up to you.
but i guess if there's something i would rather be compiler specific and
therefor this question won't belong here:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top