0

执行以下匿名结构时出现以下错误:

error: missing braces around initializer [-Werror=missing-braces]

如果我将“消息”换成像“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 的新手,所以在这里道歉。

4

1 回答 1

1

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);
于 2014-02-16T17:05:29.300 回答