I have the following structs
:
typedef struct {
char name[25];
} Piece;
typedef struct {
int num; //number of positions *piece will have
Piece *piece;
} Category;
I'm creating a function that fills the structs with information from a text file. How can I iterate this dynamic structures?
On static variables, for example Category category[50];
I would declare an iterator (int i=0;
) and move around the array doing category[i] = ...
.
What would be the equivalent with this dynamic structures?
This is a schema on how my function works:
void foo (Category *category) {
int num_of_categories = 5; //It won't be 5 always
category = (Category*)malloc(sizeof(Category)*num_of_category);
while () {
category->num = ...;
category->piece = (Piece*)malloc(sizeof(Piece)*category->num);
while () {
category->piece->name = ...;
//How to go to the next piece position?
}
//How to go to the next category position?
}