This if ((int) k == EOF) is a problem in load. EOF will never be "read" into k. EOF is the return value of fscanf. From man fscanf
These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.
The value EOF is returned ...