void mystrcat(char* to,const char* from) {
while (*to) to++;
while (*from) *to++ = *from++;
*to = '\0';
}
int main() {
char addthis[]= "rest of the sentence";
char start_of[] = "going to add ";
mystrcat(start_of,addthis);
cout << "after strcat(): " << start_of<< endl;
}
即使我替换了要遵循的功能mystrcat,行为也相同。
char* mystrcat(char* to,const char* from) {
while (*to) to++;
while (*from) *to++ = *from++;
*to = '\0';
return to;
}
对我来说很奇怪,当我调用mystrcat时,我没有分配给char *仍然没有编译器的抱怨。我在这里想念什么?后续您是否可以使用无效的返回类型优化我的代码