This link should give you one big tip as to why your initiate_labels function doesn't work fine: FAQ > Why it's bad to use feof() to control a loop - Cprogramming.com.

You use a lot of magic...