- got my binary heap refactored and working after your email, thanks!
- ran into a lot of errors I don't quite understand trying to add functionality on my family-tree
- I was attempting to create a list of child nodes for a given parent, given an array of child names, the parent node, and the amount of children to be added
- My first error was just passing the proper data types, i kept getting warnings about passing the wrong pointer types.
- This answer helped: https://cboard.cprogramming.com/c-programming/88153-how-pass-array-strings-function-argument.html
- I built this simple example to figure out how to pass stuff properly:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void printKids(char *kids[], int length){
int i;
for (i=0;i<length;i++){
printf("%s \n", kids[i]);
}
}
int main(){
char *kids[] = {"Option 1", "Option 2"};
int length = 2;
printKids(kids, length);
return 0;
}
- My next error was a seg fault, I'm not quite sure why, but maybe initiating all the nodes with the same variable name is a nono:
node addChild(node person, char *title[], int amount){
int i;
for (i=0;i<amount;i++){
node child = newNode(title[i]);
person->children[i] = child;
person->children[i]->father = person;
person->children[i]->mother = person->spouse;
}
person->child_amount += amount;
}
- My next attempt to refactor my code was to initiate the child nodes manually, then create a function that sets the child and parent relationships. This also failed. Here was that attempt:
void addChild(node father, node child){
father->children[father->child_amount] = child;
child->father = father;
child->mother = father->spouse;
father->child_amount = father->child_amount + 1;
}