Need strnlen().
Bill Crews
bc at cyb-eng.UUCP
Thu Nov 21 00:02:41 AEST 1985
> One should never allow a character array to not have a null terminating byte.
> Doing things like this should be automatic. Besides, usually when the program
> dumps core, one usually can find the problem readily. Also, if I am not
> mistaken, having character arrays that do not have terminating null bytes
> will cause problems with many other funtions e.g printf(). printf() (or
> maybe _doprint() I'm not sure which) will keep printing characters until they
> hit that null byte, but they probably won't find it where it should be.
> Unless I'm wrong, making sure strings are null terminated should be as
> automatic as making sure that you aren't trying to use NULL pointers or
> that malloc() returns a valid pointer.
It should be obvious that one is sometimes governed by external
constraints, such as the format of a directory entry. If a file or
directory entry format contains a fixed-length field which contains
textual data that can fill the entire field, one must deal with it
somehow.
--
- bc -
..!{seismo,topaz,gatech,nbires,ihnp4}!ut-sally!cyb-eng!bc (512) 835-2266
More information about the Comp.lang.c
mailing list