These are some stupid mistakes I made programming C.
I used strlen ("\0") in malloc as a substitute for 1. This is stupid because it gives a value of zero. The correct way to do this is to write sizeof ((char) '\0').
strlen ("\0")
malloc
sizeof ((char) '\0')