#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
    char a[100],b[100],*c;
    int i,j,k=0,l=0,lena,lenb,lenc;
    printf("Please input the first word:\n");
    gets(a);
    printf("Please input the second word:\n");
    gets(b);
    lena=strlen(a);
    lenb=strlen(b);
    c=(char *)malloc((lena+lenb-1)*sizeof(char));              //向内存申请适合的空间
    lenc=strlen(c);
    for (j=0;j<=lena-1;j++)
    {
        c[k]=a[j];
        k++;
    }
    for (i=lena;i<lenc;i++)
    {
        c[i]=b[l];
        l++;
    }
    puts(c);
    return 0;
}

或者可以使用

int lena = strlen(stra);
int lenb = strlen(strb);
for(int i = 0; i &lt; lenb; i++)
	stra[lena + i] = stra[i];
stra[lena + lenb] = '\0';

以下为自写函数达到同样效果

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void lianjie(char a[],char b[])
{
    char *c;
	int i,j,k=0,l=0,lena,lenb,lenc;
    lena=strlen(a);
	lenb=strlen(b);
	c=(char *)malloc((lena+lenb-1)*sizeof(char));
    lenc=strlen(c);
    for (j=0;j<=lena-1;j++)
	{
		c[k]=a[j];
	    k++;
	}
	for (i=lena;i<lenc;i++)
	{
		c[i]=b[l];
		l++;
	}
    puts(c);
}
 
int main()
{
	char a[100],b[100];
	printf("Please input the first word:\n");
	gets(a);
	printf("Please input the second word:\n");
    gets(b);
	lianjie(a,b);
	return 0;
}