编写一个程序,将两个字符串连接起来,不要用strcat 或 strncat 函数。

编写一个程序,将两个字符串连接起来,不要用strcat 或 strncat 函数。
在这里插入图片描述

更多资料请点击:我的目录

#include <stdio.h>

int main()
{
   char str1[120],str2[120];	//char数组大小最大为120
   int i=0,j=0;
   printf("请输入第一个字符串:");
   scanf("%s",str1);			//因要给整个数组输入字符,不需要带&地址符,带&特指某一位
   printf("\n请输入第二个字符串:");
   scanf("%s",str2);
   while(str1[i]!='\0')			//检验数组位是否为空
      i++;						//不为空时,i+1
   while(str1[j]!='\0')			//检验数组位是否为空
	  {
	     str1[i]=str2[j];		//将第二个字符数组添加到第一个字符数组后面
	     i++;
	     j++;
	  }
  str1[i]='\0';
  printf("\n两个字符串连接后:%s \n",str1);
} 

更多资料请点击:我的目录

发布了75 篇原创文章 · 获赞 35 · 访问量 5929

猜你喜欢

转载自blog.csdn.net/weixin_43793181/article/details/103914272