出于某种原因,每当我尝试将 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]
我能做些什么来解决这个问题?