C Programming

C program to concatenate two strings With Algorithm

Concatenation of two strings means to add two strings and make it a single unit or term. In c programming, we can easily concatenate two strings using strcat() function. This is a special type of function available in string.h library. It is generally used to add two strings. For the implementation of strcat() function in our program, firstly we have to declare the header file which includes that function.

In simple words, concatenation of two string means adding two strings to make it one.

For example:

1st string – Super

2nd string – Computer

Concatenated string – SuperComputer

Algorithm- ( concatenate two strings in C)

  1. Start
  2. Accept 1st string.
  3. Accept 2nd String.
  4. Concatenate the strings.
  5. Print the result.
  6. End

Program to concatenate two strings using strcat() function

#include<stdio.h>
#include<conio.h>
#include<string.h>

int main()
{
char str1[20],str2[20];
printf("Enter the first string :\n");
scanf("%s",&str1);
printf("Enter the secode string :\n");
scanf("%s",&str2);
strcat(str1,str2);
printf("The concatenated string is %s\n",str1);

getch();
}

Leave a Reply