出於某種原因,我得到一個編譯錯誤,每當我嘗試C字符串的值設置爲一個字符串:C字符串的值設置爲一個字符串
#include <stdio.h>
int main(void) {
char hi[] = "Now I'm initializing a string.";
hi = "This line doesn't work!"; //this is the line that produced the compiler error
return 0;
}
而且,這些都是編譯器錯誤:
prog.c: In function ‘main’:
prog.c:5:8: error: incompatible types when assigning to type ‘char[31]’ from type ‘char *’
prog.c:4:10: warning: variable ‘hi’ set but not used [-Wunused-but-set-variable]
我該怎麼辦才能解決這個問題?
@OliCharlesworth看起來,另一個問題比這個更簡單(而且不容易閱讀),所以我不確定這些問題是否應該合併。 – 2013-04-09 19:59:16