gpt4 book ai didi

c++ - 如何修复我的 strcat 函数中的错误

转载 作者:行者123 更新时间:2023-11-30 04:16:54 25 4
gpt4 key购买 nike

下面的代码在我的头文件中:

char mystrcat(char *s1, const char *s2) //strcat function
{
mystrcpy(s1 + mystrlen(s1), s2);
return s1;
}

错误是return s1; “返回值类型与函数类型不匹配。”我知道 strcat 函数将源字符串的拷贝附加到目标字符串,但我将如何修复此错误。我代码的另一部分在 main.cpp 中。如果您需要更多代码,请告诉我。

最佳答案

你的签名应该是这样的

char* mystrcat(char *s1, const char *s2)
// ^~~~~~ Note the pointer

关于c++ - 如何修复我的 strcat 函数中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17459186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com