In this example, we will concatenate two strings using multiple functions.
#include<stdio.h>
void main(void)
{
char str1[25],str2[25];
int i=0,j=0;
printf("\nEnter First String:");
gets(str1);
printf("\nEnter Second String:");
gets(str2);
while(str1[i]!='\0')
i++;
while(str2[j]!='\0')
{
str1[i]=str2[j];
j++;
i++;
}
str1[i]='\0';
printf("\nConcatenated String is %s",str1);
}
Output :
Enter First String:Hello
Enter Second String:World
Concatenated String is HelloWorld
#include <stdio.h>
#include <string.h>
int main()
{
char destination[] = "Hello ";
char source[] = "World!";
strcat(destination,source);
printf("Concatenated String: %s\n", destination);
return 0;
}
Output :
Concatenated String: Hello World!
concat() function is used for concatenate string and it's a in-built function provided by c programming. We must include <string.h> heder file to use this function.
Ask anything about this examples