我在我的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