used feof instead of global variable