String Copy in C Program

ஒரு string variable-லில் இருந்து மற்றொரு string variable-க்கு strcpy() என்ற function-ஐ பயன்படுத்தி values-ஐ copy செய்வது string copy ஆகும்.

Syntax for string copy

strcpy(string_copy_to, string_copy_from);

Example

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main(){
    char str1[]="Hindi songs";
    char str2[]= "Tamil songs";
    char str3[30];
    printf("\n Before copy, str1 value is %s ",str1);

    strcpy(str1,str2); //copy from str2 to str1
    printf("\n After copy, str1 value is %s ",str1);

    strcpy(str3,"Welcome");
    printf("\n After copy, str3 value is %s ",str3);

return 0;
}

Output:

Before copy, str1 value is Hindi songs
After copy, str1 value is Tamil songs
After copy, str3 value is Welcome

Comments