strcpy(3) - NetBSD Manual Pages

Command: Section: Arch: Collection:  
STRCPY(3)               NetBSD Library Functions Manual              STRCPY(3)

strcpy, strncpy -- copy strings
Standard C Library (libc, -lc)
#include <string.h> char * strcpy(char * restrict dst, const char * restrict src); char * strncpy(char * restrict dst, const char * restrict src, size_t len);
The strcpy() and strncpy() functions copy the string src to dst (includ- ing the terminating `\0' character). The strncpy() function copies not more than len characters into dst, appending `\0' characters if src is less than len characters long, and not terminating dst if src is len or more characters long.
The strcpy() and strncpy() functions return dst.
The following sets ``chararray'' to ``abc\0\0\0''. (void)strncpy(chararray, "abc", 6); The following sets ``chararray'' to ``abcdef'' and does not nul-terminate chararray because the source string is >= the length parameter. strncpy() only nul-terminates the destination string when the length of the source string is less than the length parameter. (void)strncpy(chararray, "abcdefgh", 6); The following copies as many characters from input to buf as will fit and nul-terminates the result. Because strncpy() does not guarantee to nul- terminate the string itself, we must do this by hand. char buf[BUFSIZ]; (void)strncpy(buf, input, sizeof(buf) - 1); buf[sizeof(buf) - 1] = '\0'; Note that strlcpy(3) is a better choice for this kind of operation. The equivalent using strlcpy(3) is simply: (void)strlcpy(buf, input, sizeof(buf));
bcopy(3), memccpy(3), memcpy(3), memmove(3), strlcpy(3)
The strcpy() and strncpy() functions conform to ISO/IEC 9899:1999 (``ISO C99''). NetBSD 4.0 May 6, 2002 NetBSD 4.0
Powered by man-cgi (2021-06-01). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.