String Concatenation in C - C Program to Concatenate Two Strings



 c program to concatenate two strings

Learn C - C tutorial - c program to concatenate two strings - C examples - C programs

C Program to Concatenate Two Strings

  • Concatenate of two strings is said to be adding two strings into one.
  • The first string is "wikitechy" and the second string is ".com" then on concatenating these two strings we get the string "C programming language."

Sample Code

#include <stdio.h>
int main()
{
    char s1[100]="wikitechy", s2[100]=".com", i, j;
    printf("Enter first string:wikitechy\n ");
    printf("Enter second string:.com \n");
    for(i = 0; s1[i] != '\0'; ++i);
    for(j = 0; s2[j] != '\0'; ++j, ++i)
    {
        s1[i] = s2[j];
    }
    s1[i] = '\0';
    printf("After concatenation: %s", s1);
    return 0;
}

Output

Enter first string:wikitechy
 Enter second string:.com
After concatenation: wikitechy.com


View More Quick Examples


Related Searches to String Concatenation in C - C Program to Concatenate Two Strings