This Program copies a given String from Source to Destination without using strcpy() function in C.
/* Program to Copy a String */
#include <stdio.h>
//Main function program
int main()
{
//Declaring Source & Destination Strings
char scr[100], des[100];
printf("Enter Source String : ");
scanf("%s", scr);
int idx;
//Coping the String from Source to Destination.
for (idx=0; scr[idx] !='\0'; ++idx)
{
des[idx] = scr[idx];
}
//Appending a NULL value in the end of string.
des[idx] = '\0';
printf("Destination String is : %s\n", des);
return 0;
}
Program Output:
Post a Comment