将两个字符串连起来,不用strcat函数,新手版

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
int main()
{
	int i,m=0,n=0;
	char c1, c2;
	char str1[80], str2[20];
	printf("Input str1:\n");
	gets_s(str1);
	printf("The str1 is:\n");
	for (i = 0; (c1 = str1[i]) != '\0'; i++)
	{
		m++;
		printf("%c", str1[i]);	
	}
	printf("\n");
	printf("m=%d\n", m);
	printf("Input str2:\n");
	gets_s(str2);
	printf("The str2 is:\n");
	for (i = 0; (c2 = str2[i]) != '\0'; i++)
	{
		n++;
		printf("%c", str2[i]);	
	}
	printf("\n");
	printf("n=%d\n",n);
	if (n <= 80 - (m + 1))
	{
		printf("Now we connect str1 and str2:\n");
		for (i = 0; i < m + n; i++)
		{
			c1 = str1[i];
			c2 = str2[i];
			str1[m + i] = c2;
			printf("%c", str1[i]);
		}
	}
	else
		printf("There is an error in your input,please try again!");
	printf("\n");
	return 0;
}

    原文作者:a149979032
    原文地址: https://blog.csdn.net/a149979032/article/details/53906957
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞