我試過這段代碼:如何在C中使用putw()函數將整數寫入文本文件?
int main(void)
{
FILE *fp; // Assuming fp is initialized
putw(11,fp); /* Instead of writing 11 to the file this statement
wrote an unwanted character into the file */
/* However when I put 11 in single quotes as,
putw('11', fp);
It worked properly and wrote integer 11 into the file */
}
,這是什麼行爲,如何解釋呢?
你並沒有真正嘗試這個。該程序因未初始化的「fp」而崩潰。 – Jens
如果你的'int'是16位,你的'putw('11',fp);'只能有「工作正常」。我的32位'int'創建了一個包含'31 31 00 00'' –