I know posting the while code is not cool, but I frankly can't figure out what is wrong anymore. I should have done this with something easier than trie-structure, but since it is close to done I'd rather not start from the scratch.
When I try to run the program, I get seg fault. Valgrind errors are invalid read size of 8 on lines 87, 89, 92.
The actual code: