Updated to check fgets() return value and removed now unused variable