So, I have a list definition as a global variable:
typedef struct center {
char center_name[100];
char hostname[100];
int port;
struct center *next_center;
} center;
I need to add items to the list. But these elements that I need to add are in the file, therefore:
int main(int argc, char** argv) {
center *head = NULL;
parse(argv, head);
}
parse is a function that reads a file and adds these reading elements to a new center (all this works, it is double checked)
void parser (char** argv, center *head) {
addToCenter(newCenter, head);
}
Where:
addToCenter(center *newCenter, center *head){
if (head == null)
head = newCenter;
else {
lastelement.next_center = newCenter;
}
}
Everything works, except that the Main list is always returned as null. In other words, the link does not change. I do not understand why, because I pass a pointer to a list.
another solution, although I have to create the main list variable as a global variable, but it is better to avoid such situations.
Thanks in advance.
source
share