Use strcpy() to copy string - C String

C examples for String:String Function

Description

Use strcpy() to copy string

Demo Code

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

char source[] = "The source string.";

int main( void )
{
    char dest1[80];
    char *dest2, *dest3;

    printf("\nsource: %s", source );

    strcpy(dest1, source);//ww  w . ja v  a  2s.com
    printf("\ndest1:  %s", dest1);

    dest2 = (char *)malloc(strlen(source) +1);
    strcpy(dest2, source);
    printf("\ndest2:  %s\n", dest2);

    return 0;
}

Result


Related Tutorials