In article <o4************ ********@tornad o.tampabay.rr.c om>,
jt <jt****@hotmail .com> wrote:
True, a null terminates a string. But, what if that string happen to be a
binary file?
Then it is still terminated by the first NUL character.
If you want something that is able to hold NUL characters within it,
then you are NOT using a "string". A string is DEFINED to end
at the first NUL.
If you want to work with groupings of arbitrary binary characters
that might include NUL, then you probably want to work with an array
of char (better yet, unsigned char).
C90 does not offer any mechanism to dynamically determine "the size"
[allocated? initialized? Highest entry written to? Highest entry
read from?] of an array of char. The closest it comes to that is
that if you have declared a character array (not pointer to char!)
then within the same scope you can use sizeof to get to the size:
char foo[123]; /* sizeof(foo) would be 123 * sizeof(char) */
You can't do this across scope boundaries. For example,
int baz(char myarg[]) {
return sizeof myarg;
}
void koz(void) {
char foo[123];
printf( "size of foo was: %d\n", baz(foo) );
}
This will NOT print out 123: C89 does NOT "somehow" transmit the
"real" size when it passes an object in as an argument.
(Instead, you will find that myarg is treated as a pointer to
a character, so the size printed will be the size of a char pointer.)
C99 offers a new mechanism, the variable sized array; if that is
used (and everything is passed appropriately) then you can determine
an object size at a lower level routine.
--
Watch for our new, improved .signatures -- Wittier! Profounder! and
with less than 2 grams of Trite!