Strcat() function example program in C C++

Coding in C

#include<stdio.h>
#include<string.h>
int main()
{
    char str1[20],str2[20];
    printf("Enter string1    : ");
    scanf("%s",&str1);
    printf("Enter string2    : ");
    scanf("%s",&str2);
    strcat(str1,str2);
    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 string1    : ";
    cin>>str1;
    cout<<"Enter string2    : ";
    cin>>str2;
    strcat(str1,str2);
    cout<<"Value of string1 : "<<str1<<endl;
    cout<<"Value of string2 : "<<str2<<endl;
    return 0;
}

Output

Strcat() function example program in C C++

Published by

admin

I am a computer teacher, programmer and web developer