出于某种原因,我得到一个编译错误,每当我尝试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