#26535: 用gets好像不安全


1234567weewee457@gmail.com (weewee4571234567)


不知道Xcode用gets為何會提示

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

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


cges30901 (cges30901)


不知道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