#: 17153 S12/OS9/68000 (OSK)
23-Nov-92 03:35:24
Sb: #17143-#C Casts
Fm: Mark Griffith 76070,41
To: Bob van der Poel 76510,2203 (X)
Bob,
> I have an array of pointer to char declared in my program. Let's say it look
> like:
>
> char *items[]={"one","two","three"};
>
> Is it possible to determine the lengths of the strings at compile time? I'd
> like to be able to do something like:
>
> int len1=sizeof(items[0]);
>
> But that sets len1 to the size of the pointer (4), not the length of the
> string (3). Do I have to go through with strlen() for the whole list or is
> there a compile time method?
>
I'd say you need to use strlen() or, since you know that size of each item in
the array, make another array that holds the size of each element, or make your
items[] array two-dimensional and hard code the sizes in there. Not very
elegant, but the compiler has no way of knowing what the sizes of the elements
are since you explicitly told it they were pointer items.
/*------------- /\/\ark -------------*/
There is 1 Reply.
|