This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>. All rights reserved. Released under the GNU General Public License.
![]() |
![]() |
![]() |
![]() |
#include <string.h> char *strcat(char *dest, const char *src);
src
string to the dest
string overwriting
the terminating null character at the end of dest
, and then adds a
terminating null character. The strings should not overlap, and
the dest
buffer size should be greater or equal to
strlen(dest) + strlen(str) + 1
. Returns the dest
parameter.
char buf[8]; strcpy(buf, "desk"); strcat(buf, "top");this is the state of the
buf
array before and after the
call of strcat
(? means
any character):
#include <string.h> char *strcat(char *dest, const char *src) { char *dp = dest; while (*dp != '\0') ++dp; while ((*dp++ = *src++) != '\0') ; return dest; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char buf[7]; strcpy(buf, "abc"); strcat(buf, "def"); printf("%s\n", buf); /* Prints "abcdef". */ printf("%d\n", strlen(buf)); /* Prints "6". */ return EXIT_SUCCESS; }