You can allocate space for several structures dynamically as follows:
strnum *numbers = malloc( size * sizeof(strnum) );
Then you can use it like any regular array (basically).
It may be more convenient to use calloc instead of malloc . It selects several blocks and fills them with zeros. Note that malloc does not clear allocated memory.
strnum *numbers = calloc( size, sizeof(strnum) );
When you finish working with memory, do not forget to call free( numbers ) , which will return the allocated memory back to the memory manager.
If you are not free , when it is no longer required and allocates more and more, the amount of memory in the program will grow without a good reason, as the program continues to work. This is called a memory leak and should be avoided. This can ultimately lead to a lack of memory for the program and unpredictable results.
And don't forget to include the stdlib.h header with prototypes of memory allocation functions.
source share