Strcpy() function example program in C C++

Coding in C

#include<stdio.h>
#include<string.h>
int main()
{
    char str1[20],str2[20];
    printf("Enter a string   : ");
    scanf("%s",&str1);
    strcpy(str2,str1);
    printf("Value of string1 : %s\n",str1);
    printf("Value of string2 : %s\n",str2);
    return 0;
}

Coding in C++

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str1[20],str2[20];
    cout<<"Enter a string   : ";
    cin>>str1;
    strcpy(str2,str1);
    cout<<"Value of string1 : "<<str1<<endl;
    cout<<"Value of string2 : "<<str2<<endl;
    return 0;
}

Output

Strcpy() function example program in C C++

Published by

admin

I am a computer teacher, programmer and web developer