[問題] ubuntu_12.04版使用code::blocks編譯問題

看板C_and_CPP (C/C++)作者 (GO哲)時間13年前 (2012/09/06 17:47), 編輯推噓1(102)
留言3則, 3人參與, 最新討論串1/1
我使用ubuntu12.04版本以及免費的code::blocks10.05 編譯以下的程式 #include <stdio.h> #include <stdlib.h> int main() { char str[50]; printf("請輸入1-5的數字:"); scanf("%[1-5]",str); printf("輸入的字元為%s\n",str); fflush(stdin); printf("請輸入XYZ任一字元:"); scanf("%[XYZ]",str); printf("輸入的字元為%s\n",str); return 0; } 可是fflush(stdin);這一行並沒有把之前輸入的字元消除 所以第二段的輸入XYZ任意字元並沒有辦法輸入 str變數依然是上一段的12345數字 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.198.126.112

09/06 17:53, , 1F
google fflush stdin
09/06 17:53, 1F

09/06 18:15, , 2F
原來gcc不支援fflush,咕狗到用fgetc取代!
09/06 18:15, 2F

09/07 04:59, , 3F
是因為那行為不是標準的 不是gcc不支援
09/07 04:59, 3F
文章代碼(AID): #1GI75Aw9 (C_and_CPP)
文章代碼(AID): #1GI75Aw9 (C_and_CPP)