strcpy - Online Linux Manual PageSection : 3
Updated : 2023-02-05
Source : Linux man-pages 6.03

NAMEstpcpy, strcpy, strcat − copy or catenate a string

LIBRARYStandard C library (libc, −lc)

SYNOPSIS#include <string.h>char *stpcpy(char *restrict dst, const char *restrict src); char *strcpy(char *restrict dst, const char *restrict src); char *strcat(char *restrict dst, const char *restrict src);Feature Test Macro Requirements for glibc (see feature_test_macros(7)): stpcpy(): Since glibc 2.10: _POSIX_C_SOURCE >= 200809L Before glibc 2.10: _GNU_SOURCE

DESCRIPTIONstpcpy()
strcpy()  
These functions copy the string pointed to by src, into a string at the buffer pointed to by dst. The programmer is responsible for allocating a destination buffer large enough, that is, strlen(src) + 1. For the difference between the two functions, see RETURN VALUE.
strcat()  This function catenates the string pointed to by src, after the string pointed to by dst (overwriting its terminating null byte). The programmer is responsible for allocating a destination buffer large enough, that is, strlen(dst) + strlen(src) + 1. An implementation of these functions might be: char * stpcpy(char *restrict dst, const char *restrict src) { char *p; p = mempcpy(dst, src, strlen(src)); *p = '\0'; return p; } char * strcpy(char *restrict dst, const char *restrict src) { stpcpy(dst, src); return dst; } char * strcat(char *restrict dst, const char *restrict src) { stpcpy(dst + strlen(dst), src); return dst; }

RETURN VALUEstpcpy()  This function returns a pointer to the terminating null byte of the copied string. strcpy()
strcat()  
These functions return dst.

ATTRIBUTESFor an explanation of the terms used in this section, see attributes(7). InterfaceAttributeValue stpcpy(), strcpy(), strcat() Thread safetyMT-Safe

STANDARDSstpcpy()  POSIX.1-2008. strcpy()
strcat()  
POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD.

CAVEATSThe strings src and dst may not overlap. If the destination buffer is not large enough, the behavior is undefined. See _FORTIFY_SOURCE in feature_test_macros(7). strcat() can be very inefficient. Read about Shlemiel the painter .

EXAMPLES #include <err.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char *p; char *buf1; char *buf2; size_t len, maxsize; maxsize = strlen("Hello ") + strlen("world") + strlen("!") + 1; buf1 = malloc(sizeof(*buf1) * maxsize); if (buf1 == NULL) err(EXIT_FAILURE, "malloc()"); buf2 = malloc(sizeof(*buf2) * maxsize); if (buf2 == NULL) err(EXIT_FAILURE, "malloc()"); p = buf1; p = stpcpy(p, "Hello "); p = stpcpy(p, "world"); p = stpcpy(p, "!"); len = p − buf1; printf("[len = %zu]: ", len); puts(buf1); // "Hello world!" free(buf1); strcpy(buf2, "Hello "); strcat(buf2, "world"); strcat(buf2, "!"); len = strlen(buf2); printf("[len = %zu]: ", len); puts(buf2); // "Hello world!" free(buf2); exit(EXIT_SUCCESS); }

SEE ALSOstrdup(3), string(3), wcscpy(3), string_copying(7)
0
Johanes Gumabo
Data Size   :   15,996 byte
man-strcpy.3Build   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   13 / 200,028
Visitor ID   :     :  
Visitor IP   :   18.191.72.220   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.