fix issue#4: fwrite if condition always false