How to assign value to Struct properties in C

c, properties, struct

Solution

I'm guessing that you have the lines

Cars sedan;
sedan.x = 20;
sedan.y = 10;

outside a function. You cannot use

sedan.x = 20;
sedan.y = 10;

outside a function. Move those lines inside a function.

Another choice is to initialize the members of the `struct` using (Thanks @JonathanLeffler)

Car sedan = { .x = 20, .y = 10 };

Problem

New to C, here is a simple Struct I have created. ``` typedef struct car { float x, y; unsigned char width, height; } Cars; ``` My attempt to assign the x and y property of car: ``` Cars sedan; sedan.x = 20; sedan.y = 10; ``` Error error: expected '=', ',', ';', 'asm' or 'attribute' before '.' token Any ideas? Please help!

Original source