errors using fwrite