## 不使用库函数实现字符串的拼接
#include <stdio.h>
int main(int argc,const char* argv[])
{
char src[128] = {0};
char dest[128] = {0};
int i = 0,j = 0;
printf("请输入两个字符串:\n");
scanf("%s %s",src,dest);
printf("before:\n");
printf("src = %s\ndest = %s\n\n",src,dest);
/*
while(1)
{
if(dest[i]=='\0')
break;
i++;
}
while(1)
{
if(src[j]=='\0')
break;
dest[i] = src[j];
i++;
j++;
}
*/
/*
* while(dest[++i] != '\0');
while((src[j]!='\0') && (dest[i] = src[j]))
{
i++;
j++;
}
*/
while(dest[++i] != '\0'); //;代表空语句
while((src[j]!='\0')&&(dest[i++] = src[j++]));
dest[i] = '\0';
printf("after :\n");
printf("src = %s\ndest = %s\n",src,dest);
return 0;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交