strcpy(3) Library Functions Manual strcpy(3) NOM stpcpy, strcpy, strcat - Copier ou concatener une chaine BIBLIOTHEQUE Bibliotheque C standard (libc, -lc) SYNOPSIS #include 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); Exigences de macros de test de fonctionnalites pour la glibc (consulter feature_test_macros(7)) : stpcpy() : Depuis la glibc 2.10 : _POSIX_C_SOURCE >= 200809L Avant la glibc 2.10 : _GNU_SOURCE DESCRIPTION stpcpy() strcpy() Ces fonctions copient la chaine pointee par src dans une chaine dans le tampon pointe par dst. Le programmeur est responsable de l'allocation d'un tampon de destination suffisamment grand, c'est-a-dire strlen(src) + 1. Pour la difference entre les deux fonctions voir VALEUR RENVOYEE. strcat() Cette fonction concatene la chaine pointee par src apres la chaine pointee par dst (ecrasant son octet NULL final). Le programmeur est responsable de l'allocation d'un tampon de destination suffisamment grand, c'est-a-dire strlen(dst) + strlen(src) + 1. Une implementation de ces fonctions pourrait etre : 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; } VALEUR RENVOYEE stpcpy() Cette fonction renvoie un pointeur vers l'octet NULL final de la chaine copiee. strcpy() strcat() Ces fonctions renvoient dst. ATTRIBUTS Pour une explication des termes utilises dans cette section, consulter attributes(7). +---------------------------------+--------------------------+---------+ |Interface | Attribut | Valeur | +---------------------------------+--------------------------+---------+ |stpcpy(), strcpy(), strcat() | Securite des threads | MT-Safe | +---------------------------------+--------------------------+---------+ STANDARDS stpcpy() POSIX.1-2008. strcpy() strcat() C11, POSIX.1-2008. STANDARDS stpcpy() POSIX.1-2008. strcpy() strcat() POSIX.1-2001, C89, SVr4, 4.3BSD. AVERTISSEMENTS Les chaines src et dst ne doivent pas se chevaucher. Si le tampon de destination n'est pas assez grand, le comportement est indefini. Voir _FORTIFY_SOURCE dans feature_test_macros(7). strcat() can be very inefficient. Read about Shlemiel the painter . EXEMPLES #include #include #include #include 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); } VOIR AUSSI strdup(3), string(3), wcscpy(3), string_copying(7) TRADUCTION La traduction francaise de cette page de manuel a ete creee par Christophe Blaess , Stephan Rafin , Thierry Vignaud , Francois Micaux, Alain Portal , Jean-Philippe Guerard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas Francois , Florentin Duneau , Simon Paillard , Denis Barbier , David Prevot , Frederic Hantrais , Gregoire Scano et Jean-Pierre Giraud Cette traduction est une documentation libre ; veuillez vous reporter a la GNU General Public License version 3 concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITE LEGALE. Si vous decouvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message a . Pages du manuel de Linux 6.06 31 octobre 2023 strcpy(3)