asked in C by (6.6k points)
0 like 0 dislike
16 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

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.

1 Answer

0 like 0 dislike
answered by (6.6k 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.

Related questions

0 like 0 dislike
1 answer 52 views
0 like 0 dislike
1 answer 16 views
0 like 0 dislike
1 answer 43 views
0 like 0 dislike
1 answer 25 views
0 like 0 dislike
1 answer 48 views
0 like 0 dislike
1 answer 31 views
0 like 0 dislike
1 answer 18 views
0 like 0 dislike
1 answer 26 views
...