标签:实现 ret main char TE temp 报错 end cat
char *Mystrcat(char*str1, char* str2)
{
if (str1 == NULL || str2 == NULL)
return NULL;
char*temp = str1; //申请指向字符的指针
while (*str1 != ‘\0‘)
{
str1++; //让指针指向字符串的尾部
}
while (*str2 != ‘\0‘)
{
*str1++ = *str2++; //从尾部开始循环赋值
}
*str1 = ‘\0‘;
return temp;
}
int main()
{
char a[100] = "retwretrewte"; //数组空间要能足够保存两个字符串长度和,否则程序报错(内存溢出)
char b[] = "4125245151";
char * temp = Mystrcat(a, b);
cout << temp << endl;
return 0;
}
标签:实现 ret main char TE temp 报错 end cat
原文地址:https://www.cnblogs.com/kevinsharif/p/9112501.html