18 - WAP to Implement own strcpy() function without using strcpy() in C
This program prints the Length of String by function without using strcpy().
- This code implements a own strcpy() function to calculate the length of a given string without using strcpy()
/* Program to implement own strcpy function */ #include/* strcpy function */ 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; } /* Main program function */ int main() { /* Declaring source & destination strings */ char src_str[50]; char dest_str[50]; char *dest = NULL; printf("Enter any String = "); gets(src_str); /* Own string copy function call */ dest = own_strcpy(dest_str, src_str); printf("Destination String is : %s \n",dest); return 0; }
Program Output:
Post a Comment