diff --git a/main.go b/main.go index 55995f5..735cd53 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,17 @@ func print_children(heading *heading, headings []heading) { } } +func print_children_recursive(heading *heading, headings []heading) { + //fmt.Printf("pointer of parent: %p\n", heading) + + for index, _ := range headings { + if headings[index].parent == heading { + fmt.Printf("Child of parent %p: %s\n", heading, headings[index].text) + print_children_recursive(&headings[index], headings) + } + } +} + func main() { file_content_raw, err := os.ReadFile(os.Args[1]) @@ -107,7 +118,9 @@ func main() { //print_children(nil, headings) // print all children of the second header - print_children(&headings[1], headings) + //print_children(&headings[1], headings) + + print_children_recursive(nil, headings) fmt.Printf("%v\n", headings)