recursively printing children works

This commit is contained in:
bjt-user 2024-05-01 15:57:29 +02:00
parent 0e61abb6cc
commit 5dc6ce8daa

15
main.go
View File

@ -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() { func main() {
file_content_raw, err := os.ReadFile(os.Args[1]) file_content_raw, err := os.ReadFile(os.Args[1])
@ -107,7 +118,9 @@ func main() {
//print_children(nil, headings) //print_children(nil, headings)
// print all children of the second header // 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) fmt.Printf("%v\n", headings)