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

Discussion in 'C++' started by sigi, Jul 3, 2005.

  1. sigi

    sigi Guest

    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:)
     
    sigi, Jul 3, 2005
    #1
    1. Advertising

  2. sigi

    benben Guest

    "sigi" <> wrote in message
    news:...
    > 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:)
    >
    >
    >
     
    benben, Jul 3, 2005
    #2
    1. Advertising

  3. sigi

    Rolf Magnus Guest

    sigi wrote:

    > 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.
     
    Rolf Magnus, Jul 3, 2005
    #3
  4. sigi

    sigi Guest

    a my lord, for sure...

    thanks.

    "Rolf Magnus" <> wrote in message
    news:da8pji$hi8$01$-online.com...
    > sigi wrote:
    >
    >> 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.
    >
     
    sigi, Jul 3, 2005
    #4
  5. sigi

    sigi Guest

    what a dumb question, sorry...

    "benben" <> wrote in message
    news:42c7e6e3$0$20028$...
    >
    > "sigi" <> wrote in message
    > news:...
    >> 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:)
    >>
    >>
    >>

    >
    >
     
    sigi, Jul 3, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wwj
    Replies:
    7
    Views:
    558
  2. lovecreatesbeauty
    Replies:
    1
    Views:
    1,058
    Ian Collins
    May 9, 2006
  3. Replies:
    3
    Views:
    737
  4. davidb
    Replies:
    0
    Views:
    764
    davidb
    Sep 1, 2006
  5. davidb
    Replies:
    6
    Views:
    1,554
    Default User
    Sep 1, 2006
Loading...

Share This Page