User defined function of strcpy()

User defined function of strcpy()

strcpy is used to copies a string to another.

Prototype of strcpy() function : char* strcpy(char *dest, const char *src);

Program of strcpy()

 #include <stdio.h>

char* own_strcpy(char *dest, const char *src)


    /* Storing initial address of dest pointer */

    char *temp = dest;

    /* copy of string from source to destination up to null terminated character */

    while (*dest++ = *src++);

    return temp;


int main()


    char src_str[50];

    char dest_str[50];

    char *dest = NULL;

    printf(“Enter any string = “);


    /* Own string copy function call */

    dest = own_strcpy(dest_str, src_str);

    printf(“Destination string is = %s”,dest);

    return 0;



$ ./a.exe

Enter any string =

Destination string is =

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.