*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->OpenBSD man pages -> strncpy (3)              
Title
Content
Arch
Section
 

STRCPY(3)

Contents


NAME    [Toc]    [Back]

     strcpy, strncpy - copy strings

SYNOPSIS    [Toc]    [Back]

     #include <string.h>

     char *
     strcpy(char *dst, const char *src);

     char *
     strncpy(char *dst, const char *src, size_t len);

DESCRIPTION    [Toc]    [Back]

     The strcpy() and strncpy() functions copy the string src  to
dst (including
 the terminating ` ' character).

     strncpy()  copies not more than len characters into dst, appending ` '
     characters if src is less than len characters long, and  not
terminating
     dst if the length of src is greater than or equal to len.

RETURN VALUES    [Toc]    [Back]

     The strcpy() and strncpy() functions return dst.

EXAMPLES    [Toc]    [Back]

     The following sets chararray to ``abc   '':

           (void)strncpy(chararray, "abc", 6);

     The following sets chararray to ``abcdef'' and does not null
terminate
     chararray because the source string is >= the length parameter.
     strncpy()  only  null 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
     null  terminates  the  result.   Because  strncpy() does not
guarantee to null
     terminate the string itself, we must do this by hand.

           char buf[BUFSIZ];

           (void)strncpy(buf, input, sizeof(buf) - 1);
           buf[sizeof(buf) - 1] = ' ';

     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));

SEE ALSO    [Toc]    [Back]

      
      
     bcopy(3), memccpy(3), memcpy(3), memmove(3), strlcpy(3)

STANDARDS    [Toc]    [Back]

     The   strcpy()  and  strncpy()  functions  conform  to  ANSI
X3.159-1989 (``ANSI
     C'').

OpenBSD     3.6                           June      29,      1991
[ Back ]
 Similar pages
Name OS Title
bcopy Linux copy byte strings
strccpy IRIX copy strings, compressing or expanding escape codes
xstr OpenBSD extract strings from C programs to implement shared strings
xstr NetBSD extract strings from C programs to implement shared strings
xstr Tru64 Extracts strings from C programs to implement shared strings
xstr FreeBSD extract strings from C programs to implement shared strings
xstr IRIX extract strings from C programs to implement shared strings
xstr HP-UX extract strings from C programs to implement shared strings
scp FreeBSD secure copy (remote file copy program)
scp OpenBSD secure copy (remote file copy program)
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service