in C by (9.4k points)
0 like 0 dislike
33 views
How I can to create object of struct in C (don't C++)?

create object of struct in c

create new object using structure in c

1 Answer

0 like 0 dislike
by (9.4k points) edited by

You just declare a pointer:

Window *win;

And try to write there in the next lines, while the pointer still doesn't point to any valid object:

win->topX = topX;

You probably wanted to create a new object:

Window *win = (Window*)malloc(sizeof(Window));

Keep in mind that

Foo *bar = (Foo*)malloc(sizeof(Foo));

and

Foo *bar;

is a different things.

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.