#include<stdio.h>
void main(){
//输入两个字符串并连接 不能使用库函数strcat
//字符串str1
printf("please enter string str1\n");
char str1[51] = {'\0'};
gets(str1);
printf("str1 enter end\n");
//字符串str2
printf("please enter string str2\n");
char str2[51] = {'\0'};
gets(str2);
printf("str2 enter end\n");
printf("\n");
//指定str2需要连接到str1的字符数
printf("----------------string enter end----------------\n");
printf("\n");
printf("please enter substring numbers\n");
int num = 0;
scanf("%d",&num);
printf("\n");
printf("----------------substring enter end----------------\n");
//循环找出str1的字符串结束标识
for(int i = 0; i < 51;i++){
if(str1[i] == '\0'){
for(int k =0; str2[k] != '\0'; k++){
str1[i+k] = str2[k];
num--;
if(num == 0)break;
}
break;
}
}
printf("\n");
printf("\n");
printf("----------------Reasult----------------\n");
printf("%s\n",str1);
}
c语言 连接两个字符串不使用库函数
最新推荐文章于 2024-07-11 11:00:00 发布