Question

Getting the following error when doing the anonymous struct below:

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

If I swap 'message' out for a static string like 'lalala', that works fine.

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;
}

Any ideas? And yes I'm new to C, so apologies there.

Was it helpful?

Solution

C is not allow like this

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

use strcpy (or strncpy)

E.g.

strcpy(carray, cp);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top