I can't figure out how to quickly initialize a bunch of structs. I'm getting stuck on needing to assign them a character array. The code is as follows:
typedef struct {
char name[5];
} s;
s * buildS() {
char names[2][5] = { "name", "foo"};
s stru[2];
for (int i = 0; i < 2; i++) {
s tmp;
tmp.name = names + i;
stru[i] = tmp;
}
return stru;
}
The s.name = names + 1; line is where the error appears:
error: incompatible types when assigning to type 'char[5]' from type 'char (*)[5]'
What am I missing here? Can I assign an internal array to a struct's array field?
Edit: fixed to crappy syntax in the code, my bad
strncpy(s.name, &names[i], strlen(names[i]));?