check fwrite return value