我有以下结构体:
struct example_struct {
int number ;
char word[100]
}
我在代码中将其初始化为一个常量结构体。
const struct example_struct example {
.number = 5
} ;
strcpy(example.word, "some_string") ;
当我尝试编译我的代码时,它会给我一个警告:
"警告:传递给strcpy的第1个参数从指针目标类型中丢弃了const限定符"
我意识到当我将结构体声明为const时,不应该尝试为其赋值,但我也不能在结构体内部使用stringcpy。有没有办法在C语言中为const结构体的元素分配字符串?