strncpy
phil%rice at sri-unix.UUCP
phil%rice at sri-unix.UUCP
Fri Feb 24 11:28:49 AEST 1984
From: William LeFebvre <phil at rice>
"strncpy" copies EXACTLY n characters, regardless of the length of
either string. Some programs rely on this particular (some would say
peculiar) heuristic of "strncpy". To change it would invite disaster.
If you need a function that does a "strncpy" but insures that "s1" is
null terminated, I suggest that you write your own and call it
something besides "strncpy". All the functions in the str* family are
easy to duplicate. Personally, I have frequently added a function
called "strecpy" which performs the same function as "strcpy" except
that it returns a pointer to the null byte in "s1" rather than the
beginning. I found this handy when I wanted to do a bunch of strcats in
a row.
William LeFebvre
Department of Mathematical Sciences
Rice University
<phil at rice>
More information about the Comp.unix
mailing list