#26535: 用gets好像不安全


1234567weewee457@gmail.com (weewee4571234567)

學校 : 桃園市私立復旦高級中學
編號 : 92174
來源 : [111.71.213.222]
最後登入時間 :
2025-02-06 19:01:18

不知道Xcode用gets為何會提示

warning: this program uses gets(), which is unsafe.

#26926: Re:用gets好像不安全


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.12.66.21]
最後登入時間 :
2025-04-20 17:19:22

不知道Xcode用gets為何會提示

warning: this program uses gets(), which is unsafe.


因為gets()無法限制字串長度,可能會造成overflow,scanf("%s", s)也是一樣,所以有人建議用fgets()。

可參考https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used