+ 5

How can I create a dynamic structure in C?

Lets say I have a system which can have any number of states which the user will specify and I need to store these states in a structure. struct states { char state1; char state2; : : }; How can I do that?

19th Feb 2019, 8:48 AM
Infinity
Infinity - avatar
2 Respuestas
+ 2
Such a thing isn't possible but maybe you're overthinking it. If all your states are of type `char`, then you can save all of them in a big string (`char*`)!
19th Feb 2019, 9:19 AM
Schindlabua
Schindlabua - avatar
+ 4
Schindlabua Actually yes, I am overthinking it 😅 But then, I have figured out that I should create just one structure and allocate it memory multiple times using malloc (This doesn't directly do what I want but I can manage)
19th Feb 2019, 9:28 AM
Infinity
Infinity - avatar