[問題] stdin問題請益
Linux
GCC
http://man7.org/tlpi/code/online/dist/altio/t_select.c.html
因為程式沒有任何讀取的動作,所以stdin buffer裡面的資料會導到shell上。
https://imgur.com/Mua5xCJ
比如只按enter 命令提示就會再跳一個$
如果是ls + enter, ls 就會導到shell,然後變成shell command。
在程式exit(EXIT_SUCCESS)前放一個getchar(),單一字元就不會導到shell。
但是如果是輸入ls再加enter,為什麼s + 換行符並沒有導到shell上?
getchar 不是只吃一個字元而已嗎,剩下的還再buffer裏面?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.120.33.176 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1575532214.A.75D.html
推
12/05 16:14,
4年前
, 1F
12/05 16:14, 1F
→
12/05 16:17,
4年前
, 2F
12/05 16:17, 2F
→
12/05 16:17,
4年前
, 3F
12/05 16:17, 3F
→
12/05 16:19,
4年前
, 4F
12/05 16:19, 4F
→
12/05 16:33,
4年前
, 5F
12/05 16:33, 5F
推
12/05 22:57,
4年前
, 6F
12/05 22:57, 6F
→
12/06 08:04,
4年前
, 7F
12/06 08:04, 7F
推
12/06 08:29,
4年前
, 8F
12/06 08:29, 8F
→
12/06 08:30,
4年前
, 9F
12/06 08:30, 9F
→
12/06 08:31,
4年前
, 10F
12/06 08:31, 10F
→
12/06 19:56,
4年前
, 11F
12/06 19:56, 11F