Just trying to get some code to work involving pointers, functions and recursion:
Node * root = malloc(sizeof(Node)); root->data = "1"; root->next = NULL; root->child = NULL; Node * G = NULL; BuildGraph(root, &G); printf("Root is: %d\n", root->data); Print(G, ">>"); // Custom Print function And BuildGraph:
void BuildGraph(Node * head, Node ** G) { if (head->child == NULL) { // No child printf("Head has no child! %d\n", head->data); Push(head, &G); Print(G, ">>"); return; } BuildGraph(head->child, &G); return; } And so when I run the program, my output goes like this:
Head has no child! 1 // printf in BuildGraph G: 1>> // Print(G, ">>") in BuildGraph Root is: 1 G is empty! // Print(G, ">>") in main Anyone know the reason G is not carrying over into main?
Thanks.