系列文章目录
c语言字符串追加
c语言字符串追加
- 系列文章目录
- c语言字符串追加
c语言字符串追加
int main()
{
char arr1[] = "hello";
char arr2[] = "world";
char arrbuf[100] = { 0 };//全部初始化'\0'
int index = 0;
while (arr1[index]!= '\0')
{
//1、将非\0的字符添加到arrbuf
arrbuf[index] = arr1[index];
//2、计数器增长
index++;
}
int len = sizeof(arr1) - 1;
while (arr2[index - len] != '\0')
{
arrbuf[index] = arr2[index - len];
index++;
}
//添加字符串结束标志
arrbuf[index] = '\0';
printf("%s", &arrbuf);
}
END