Concatenate Two String C – Program

Concatenate Two String C – Program

write a  c program for concatenate two given string.

Concatenate two string means joint second string after first string. Suppose we have two string the first sting is “meera” and second string is “academy”, the concatenate string is “meeraacademy”

In C Program STRCAT is the inbuilt function to joint two string. Example of STRCAT

Example for concatenate two string without use of STRCAT function.

#include<stdio.h>

int main()
{
 char str1[100], str2[100];
 int i, j;
 printf("Please, enter the first string = ");
 scanf("%s",str1); 

 printf("\nPlease, enter the second string = ");
 scanf("%s",str2); 

 for(i=0; str1[i]!='\0'; ++i)
  for(j=0; str2[j]!='\0'; ++j, ++i)
  {
   str1[i]=str2[j];
  }
 str1[i]='\0';
 
 printf("\nThe Concatenated string is = %s",str1);

 return 0;
}

The output of concatenate string C Program is :

Please, enter the first string = m e e r a

Please, enter the second string = a c a d e m y

The Concatenated string is = m e e r a a c a d e m y

 

Leave a Reply

Your email address will not be published. Required fields are marked *