C Language Example - Concatenating Strings
Use strcat() to concatenate two strings.
Example
#include <stdio.h>
int main()
{
char s1[100], s2[100], i, j;
printf("Enter the first string:");
scanf("%s", s1);
printf("Enter the second string:");
scanf("%s", s2);
// Calculate the length of string s1
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;
}
The output result is:
输入第一个字符串: google 输入第二个字符串: example 连接后: googleexampleother extensions