Use sizeof(char) instead of "1" in fwrite().