hi guys i'm having the following problem with my code.
I have a struct that represents a list :
Code:
struct list_of_elements{
int number_of_elements; //counter of list elements
A* head; //1st element of the list
A* tail; //last element of the list
};
So from the above my list contains elements of type A which is another struct.
Code:
struct A{
int telephone_num;
char* name;
};
When I initialize the list here's what I do:
Code:
struct list_of_elements *loe = (struct list_of_elements*) malloc ( 5* sizeof(struct A*)); //I want the max size of the list to be 5 elements
for(int j=0;j<5;j++){
list_of_elements[i] = NULL;
}
list_of_elements->head=NULL;
list_of_elements->tail=NULL;
list_of_elements->number_of_elements=0;
I have 2 questions:
a)Is the initialization of Block correct as it contains an element of type char* which at the moment is undefined?
b)Is the use of malloc correct?In general I'm a bit confused with the whole thing...
Thanks in advance!