For faster navigation, this Iframe is preloading the Wikiwand page for strcpy.

strcpy

Función incluida dentro del archivo de cabecera de constantes string.h del lenguaje de programación C.

Prototipo

[editar]
char *strcpy ( char *destino, const char *origen );

Parámetros

[editar]
char *destino
char *origen

Descripción

[editar]

Copia la cadena apuntada por origen en la cadena apuntada por destino.

Ejemplo

[editar]
char * origen = "Hola mundo"; //Se inicializa la variable origen con el valor indicado

char destino[strlen(origen)+1]; //El puntero destino debe contener suficiente espacio para copiar sobre la zona de memoria a la que apunta, la cadena apuntada por origen

strcpy (destino, origen); // Después de realizar esta operación la variable ''destino'' tendrá el valor "Hola mundo"


Ejemplos en C++

[editar]
#include <iostream>
#include <cstring>

using namespace std;

int main(){
 float venta[100], auxV, suma=0;
 char vendedor[100][30], aux[30];
 int i, j, n;
 cout << "Ingrese la cantidad de Vendedores:";
 cin >> n;
 for (i = 0; i < n ; i++){
     cout << "Vendedor "<<i+1<<endl;
     cout << "Nombre Vendedor:";
     cin >> vendedor[i];
     cout << "Importe de su Venta:";
     cin >> venta[i];
     suma += venta[i];
 }
 for(i = 0; i < n-1; i++)
    for(j = i+1; j < n; j++)
    if (venta[i] > venta[j]){
         auxV = venta[i];
         venta[i] = venta[j];
         venta[j] = auxV;
         strcpy(aux, vendedor[i]);
         strcpy(vendedor[i], vendedor[j]);
         strcpy(vendedor[j], aux);
    }
 cout << "Venta Maxima: " << venta[n-1] << " Realizado por " << vendedor[n-1] << endl;
 cout << "Venta Minima: " << venta[0] << " Realizado por " << vendedor[0] << endl;
 cout << "Venta Promedio:" << suma << endl;
 cin.get();
 return 0;
}
  • OpenBSD dispone de una versión más segura llamada strlcpy: una variante de strlcpy que trunca el resultado para que quepa en el búfer de destino[1]

Referencias

[editar]
  1. Miller, Todd C.; De Raadt, Theo (6 de junio de 1999). strlcpy and strlcat - Consistent, Safe, String Copy and Concatenation. USENIX Annual Technical Conference. Monterey, California. Consultado el 13 de diciembre de 2011. 

Enlaces externos

[editar]

Descripción de la función Strcpy en C con clase

{{bottomLinkPreText}} {{bottomLinkText}}
strcpy
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?