0 like 0 dislike
5 views
asked in C by (5.3k points)
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 (5.3k 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 41 views
0 like 0 dislike
1 answer 10 views
0 like 0 dislike
1 answer 35 views
0 like 0 dislike
1 answer 14 views
0 like 0 dislike
1 answer 33 views
0 like 0 dislike
1 answer 24 views
0 like 0 dislike
1 answer 5 views
0 like 0 dislike
1 answer 12 views
0 like 0 dislike
1 answer 16 views
0 like 0 dislike
1 answer 43 views
...