c – Error: Conversion to non-scalar type requested

c – Error: Conversion to non-scalar type requested

You cant cast anything to a structure type. What I presume you meant to write is:

dungeon *d1 = (dungeon *)malloc(sizeof(dungeon));

But please dont cast the return value of malloc() in a C program.

dungeon *d1 = malloc(sizeof(dungeon));

Will work just fine and wont hide #include bugs from you.

malloc returns a pointer, so probably what you want is the following:

dungeon* d1 = malloc(sizeof(dungeon));

Here is what malloc looks like:

void *malloc( size_t size );

As you can see it return void*, however you shouldnt cast the return value.

c – Error: Conversion to non-scalar type requested

The memory assigned by malloc must be stored in a pointer to an object, not in the object itself:

dungeon *d1 = malloc(sizeof(dungeon));

Leave a Reply

Your email address will not be published.