Just a very brief question really which stemmed from another post, if I were to access my char *number within my ListNode, from my TreeNode, so that each TreeNode each has its own linked list of numbers, would I access it as follows ( where TreeNode *root):
root->name = strdup(name); root->numbers->number = strdup(number);
Cheers!
typedef struct ListNode {
char *number;
struct ListNode *next;
}ListNode;
typedef struct TreeNode {
char *name;
ListNode *numbers;
struct TreeNode *left;
struct TreeNode *right;
}TreeNode;
EDIT: Here is my function to add a TreeNode and List to that Node:
int main(void) {
char my_string[50], name[25], number[25];
TreeNode *root = NULL;
ListNode *list = NULL;
while ((fgets(my_string, 50, stdin)) != NULL) {
if (my_string[0] == '.')
break;
sscanf(my_string, "%s %s", name, number);
root = AddNode(root, list, name, number);
}
return 0;
}
TreeNode* AddNode(TreeNode *root, ListNode *list, char *name, char *number) {
int comparison;
if ( root == NULL) {
root = (TreeNode *)malloc(sizeof(TreeNode));
list = (ListNode *)malloc(sizeof(ListNode));
root->name = strdup(name); root->numbers->number = strdup(number);
root->left = root->right = NULL;