◐ Shell
clean mode source ↗

strcpy - cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Definido no cabeçalho

<string.h>

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

Copia a seqüência de bytes apontado pela variável src para o array de bytes apontado pela variável dest.

Original:

Copies the byte string pointed to by src to byte string, pointed to by dest.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Se os strings se sobrepuserem, o comportamento é indefinido.

Original:

If the strings overlap, the behavior is undefined.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parâmetros

dest -

ponteiro para um byte string para onde será feita a cópia

Original:

pointer to the byte string to copy to

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

src -

ponteiro para o byte string de origem, terminado com o carácter nulo

Original:

pointer to the null-terminated byte string to copy from

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Valor de retorno

dest

Exemplo

#include <stdio.h>
#include <string.h>

void main(void) {
    char destino[50];
    char origem[] = "Meu primeiro string.";

    // É sua responsabilidade garantir que o string destino é grande o suficiente para
    // acomodar o string que está sendo copiado, mais o terminador, o caracter nulo ('\0').
    strcpy(destino, origem);
    printf("destino: %s\n", destino);

    // Esta cópia irá sobrepor o destino apagando os caracteres que já estão no string.
    strcpy(destino, "Eu amo C!");
    printf("destino: %s\n", destino);
}

Saída:

destino: Meu primeiro string.
destino: Eu amo C!

Veja também

copia uma certa quantidade de caracteres a partir de uma corda para outra

Original:

copies a certain amount of characters from one string to another

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(função) [edit]

copia um buffer para outro

Original:

copies one buffer to another

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(função) [edit]