fputs/puts 危险(C 语言)?
我最近在 fputs 方面遇到了麻烦:当使用 fputs 在文本文件中打印一些字符串时,我碰巧得到了除 AZ、az、0-9 之外的其他字符(不属于字符串的字符)。我绝对确保字符串都以空字符结尾。不幸的是,我无法向您提供更多信息,因为我没有亲自测试该程序,这是我收到的反馈。但当我用 fprintf 替换 fputs 后,它工作正常。
所以我的问题是:fputs 有点危险吗?你有遇到过这样的麻烦吗?
I've been having trouble with fputs lately: when printing some strings in a text file with fputs, it happens I get other characters than A-Z, a-z, 0-9 in (chars that aren't part of the string). I made absolutely sure the strings all end with the null character. Unfortunately I can't give you more information, since I did not personally test the program, that was the feedback I received. But after I replaced fputs with fprintf it worked properly.
So my question is: is fputs sort of dangerous? Have you ever had trouble with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
fputs
本身并不危险。当然,如果没有示例代码,很难说出是什么导致了您所看到的问题。fputs
is not inherently dangerous. Of course without example code its hard to say what was causing the problem you were seeing.fputs()
不是一个“危险”函数(与危险的gets()
不同)。您正在打印的字符串实际上包含最终出现在文件中的字符。没有代码,我们无法知道他们是如何到达那里的。fputs()
is not a "dangerous" function (unlikegets()
, which is dangerous). The strings you are printing actually contain the characters that end up in the file. Without code, we can't know how they got there.