C Program to Concat Two Strings

C Program to Concat Two Strings

Write C Program to Concat Two Strings

// C Program to Concat Two Strings

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

int main()
{
	char S1[] = "Code", S2[] = "Crucks";
	char S3[20];
	int i = 0,j = 0;

//	strcat(S1,S2);			// Using inbuilt function
//	printf("Concatination string is %s",S1);

    // Doing manually
	while(S1[i] != '\0')
	{
		S3[j] = S1[i];
		i++;
		j++;
	}

	i=0;
	while(S2[i] != '\0')
	{
		S3[j] = S2[i];
		i++;
		j++;
	}

	S3[j] = '\0';
	printf("String S1 :--> %s", S1);
	printf("\nString S2 :--> %s", S2);
	printf("\n\nConcatenated String :--> %s",S3);

	return 0;
}

Output:


String S1 :--> Code
String S2 :--> Crucks

Concatenated String :--> CodeCrucks