Fixed things. Also, made write/fwrite both use for loops.