我想一個值分配給我的char *
這樣的:分配值字符數組在C不工作
char *text;
struct node *ptr = head;
//start from the beginning
while(ptr != NULL)
{
text = ptr->key + ";" + ptr->data + ";\n";
ptr = ptr->next;
fprinft(f, text);
}
鍵值是char[]
和數據值的int
。
我得到以下錯誤:
Error: invalid operands to binary + (have ‘int’ and ‘char *’) text = ptr->key + ";" + ptr->data + ";\n";
有誰知道如何解決這個問題?
'strcat'是你的朋友。 –
你的編譯器肯定會告訴你一些關於這段代碼的有用信息。 – EOF
錯誤:無效的操作數爲二進制+(有'char *'和'char *') text = ptr-> key +「;」 + ptr-> data +「; \ n」; – mafioso