I have the following struct:
struct elem {
int number;
char character;
};
struct item {
struct elem element;
};
and the following function:
void init(struct item *wrapper) {
assert(wrapper != NULL);
wrapper->element = NULL;
}
item->element = NULL yields a incompatible types in assignment. Why is that? Shouldn’t setting a struct to NULL be okay?
In C
NULLis generally defined as the followingThis means that it’s a pointer value. In this case your attempting to assign a pointer (
NULL) to a non-pointer valueitem::elementand getting the appropriate message. It seems like your intent is to haveelementbe a pointer here so try the following