|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
实现strcat的功能,这样为什么不行啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
谢谢大佬们
#include <stdio.h>
#define MAX 1024
int main()
{
char str1[MAX];
char str2[MAX];
char* target1 = str1;
char* target2 = str2;
printf("Please input the first string:");
fgets(str1, MAX, stdin);
printf("Please input the second string:");
fgets(str2, MAX, stdin);
int i = 0;
while (*target1++ != '0')
{
i++;
}
char str[2 * MAX];
char* target3 = str;
int n;
for (
n = 0; n < i; n++)
{
*target3++ = *target1++;
}
for (;;)
{
if(*target2++ != '0'){*(target3 + n-2) = *target2++;}
}
printf("the sentence is:%s", str);
return 0;
}
本帖最后由 jackz007 于 2020-11-10 22:58 编辑
- #include <stdio.h>
- #define MAX 1024
- int main()
- {
- char str1[MAX] , str2[MAX] , str3[MAX * 2] ;
- int i , j , m ;
- printf("Please input the first string : ") ;
- fgets(str1 , MAX , stdin) ;
- for(m = 0 ; str1[m] ; m ++) ;
- str1[m - 1] = '\0' ;
- printf("Please input the second string : ") ;
- fgets(str2 , MAX , stdin) ;
- for(m = 0 ; str2[m] ; m ++) ;
- str2[m - 1] = '\0' ;
- for(i = 0 ; str1[i] ; i ++) str3[i] = str1[i] ;
- for(j = 0 ; str2[j] ; j ++) str3[i + j] = str2[j] ;
- str3[i + j] = '\0' ;
- printf("the sentence is:%s\n" , str3) ;
- }
复制代码
|
|