执行下面的匿名结构时出现以下错误:
错误:初始化程序周围缺少大括号 [-Werror=missing-braces]
如果我将“message”替换为“lalala”等静态字符串,效果很好。
typedef struct {
/* public: */
char message[255];
} Note;
static uint16_t local_size = 0;
static Note *notes;
Note *add_local_note(const char *_message) {
//char bla[255] = "hot hot hot";
notes[(++local_size)-1] = (Note) {
.message = _message
};
return notes;
}
有什么想法吗?是的,我是 C 语言新手,所以很抱歉。
最佳答案
C不允许这样
char *cp = "sample";
char carray[10] = cp;//NG, Type is different rather than that is not able to use the variables.
char carray[10] = "sample";// or { "test" };//OK
使用strcpy(或strncpy)
例如
strcpy(carray, cp);
关于无法通过 'error: missing braces around initializer',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21813907/