C Program to Concatenate of two strings

Concatenation:- string concatenation  is the operation of joining character strings end-to-end.

For example: “ the concatenation of “snow” and “ball” is “snowball”.

 

 

 

Let’s write a program to Concatenate two Strings.

 

 

Step 1: Let’s open Turbo C and write the following code.

//Add preprocessor

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

//Declare variable

char first[30],second[30];

// Clear screen

clrscr();

printf(“enter first string: \n”);

gets(first);

printf(“enter second string: \n”);

gets(second);

strcat(first,second);

// Print the Result

printf(“output is : %s \n”,first);

getch();

}

Step 2: Now save it and name it CONCATENATE.CPP

Step 3: Now compile it by pressing ALT+F9 or click on Compile.

Step 4: Now Run the program by pressing ALT+R then hit the enter or click on Run and see output.

Output:

concatenate output

Happy Coding.

Tags: , ,