This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>. All rights reserved. Released under the GNU General Public License.
![]() |
![]() |
![]() |
![]() |
char *strcpy(char *dest, const char *src);
src
including the terminating null character in
the buffer dest
overwriting the previous existing data.
The dest
buffer should be large enough to contain the new string. The
two strings should not overlap. Returns the dest
parameter.
char buf[12]; strcpy(buf, "hello world");this is the state of the
buf
array before and after the call of
strcpy
(? means
any character):
#include <string.h> char *strcpy(char *dest, const char *src) { char *dp = dest; while ((*dp++ = *src++) != '\0') ; return dest; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char buf[12]; strcpy(buf, "Hello world"); printf("%s\n", buf); /* Prints "Hello world". */ return EXIT_SUCCESS; }