Concatenation of string C Example Program

Concatenation of string Definition:

In computer programming, string concatenation is the operation of joining two character strings end-to-end.

Concatenation of string Explanation:

For example, the strings "snow" and "ball" may be concatenated to give "snowball".
For example, the following expression uses the "+" symbol as the concatenation operator to join two strings: "Hello, " + "World";, and has the value "Hello, World".

Example Concatenation of string Program:    

/* Example Program For Concatenation of string In C Programming Language
  little drops @ thiyagaraaj.com
  Coded By:THIYAGARAAJ MP       */

// Header Files
#include<stdio.h>
#include<conio.h>

void main()
{
	int i,j;
	char string1[20];
	char string2[20];
	char string[100];
	
	clrscr();
	printf("Enter Sring1: ");
	scanf("%s",string1);
	printf("Enter Sring2: ");
	scanf("%s",string2);
	for(i=0;string1[i]!='\0';i++)
	string[i]=string1[i];
	string[i]=' ';
	for(j=0;string2[j]!='\0';j++)
	string[i+j+1]=string2[j];
	string[i+j+1]=' ';
	printf("%s",string);
	
	getch();
}

 

 

Sample  Output:

Enter Sring1: Hello,

Enter Sring2: World

The Concatenated string is: Hello, World

 

Top Pages