Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Length of Strin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 1092 of 1099
Post > Topic >>

Length of Strings in an Arrray (at compile-time)

by "Paul" <-@[EMAIL PROTECTED] > May 5, 2008 at 04:01 PM

How do I find the length of strings within an array at compile time?

The following is not safe:

const char* MyStrings[] =
{
    "one",
    "two",
    "three",
    "end marker"
}

#define StringLength(index) MyStrings[index+1] - MyStrings[index]

Since the strings may not be placed consecutively, or in order, within
memory.

Also

#define String1 "one"
#define String2 "two"
#define String3 "three"

const char* MyStrings[] =
{
    String1,
    String2,
    String3
}

int StringLengths[] =
{
    size(String1),
    size(String2),
    size(String3)
}
is a bit too cumbersome.

Any better suggestions?

Cheers,
Paul.
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.




 3 Posts in Topic:
Length of Strings in an Arrray (at compile-time)
"Paul" <-@[E  2008-05-05 16:01:45 
Re: Length of Strings in an Arrray (at compile-time)
=?ISO-8859-1?Q?Hans-Bernh  2008-05-07 01:38:05 
Re: Length of Strings in an Arrray (at compile-time)
Jack Klein <jackklein@  2008-05-07 01:39:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 6:53:31 CDT 2008.