我在我的strjoin
代码中有错误。我的代码的路径是允许一个字符串,并返回一个以'\0'
连接两个字符串结束的字符串。无效的操作数到二进制表达式('const char *'和'const char *')c
#include "libft.h"
char *ft_strjoin(const char *s1, const char *s2)
{
char *s3;
s3 = malloc(sizeof(char) * (s1 + s2)); // I've an error in this line
s3 = ft_strcat((char *)s1, s2);
return (s3);
}
我的错误:
invalid operands to binary expression ('const char *' and 'const char *')
我不知道为什么我得到这个错误。 我在网上搜索过,我找不到如何修复它。
谢谢,我错了! – Vorbide
也许你想要'(strlen(s1)+ strlen(s2))'而不是'(s1 + s2)'? –
这段代码“(s1 + s2)'的目的究竟是什么? – alk