[閒聊] 我可以再問一個寫程式的問題嗎

作者: Wardyal (Wardyal)   2023-11-01 14:11:58
為什麼我
FILE *fp;
int tmp = 1;
fopen(fp, "test.txt", "w");
fprintf(fp, "%s\n", "apple");
fprintf(fp, "%d", tmp);
fclose(fp);
都會在fprintf %s 那行Segmentation Fault阿
就算後來換成
char *str = "apple";
也是一樣 好怪
作者: walter741225 (瓦特)   2023-11-01 14:13:00
你是不是應該先檢查fopen的結果一般都會寫判斷式確定open成功
作者: Wardyal (Wardyal)   2023-11-01 14:15:00
可是我測了很多次 都還是不行 我其他地方fprint int都沒問題主要是就算判斷失敗 我還是要寫 所以我就沒寫判斷了:0
作者: WindowDragon (貼貼)   2023-11-01 14:19:00
竟然能在這種文看到特 我流淚了
作者: kerycheng (kk)   2023-11-01 14:26:00
fopen只有給兩個輸入值吧FILE *fopen(const char *filename, const char *mode)

Links booklink

Contact Us: admin [ a t ] ucptt.com