codescracker


c

C Program to Concatenate String



« Previous Program Next Program »


Concatenate String in C

To concatenate or to append one string to another string in C programming, you have to ask to the user to enter the two string and start concatenating one string into other using strcat() function

C Programming Code to Concatenate String

Following C program ask the user to enter the two string to concatenate it using the function strcat() of string.h library. This function takes the two argument like strcat(str1, str2). Here string of str2 will be appended at the end of the string str1 :

/* C Program - Concatenate String */
		
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
	clrscr();
	char str1[50], str2[50];
	printf("Enter first string : ");
	gets(str1);
	printf("Enter second string : ");
	gets(str2);
	strcat(str1, str2);
	printf("String after concatenation is %s",str1);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program concatenate two strings

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test