fputs/puts dangerous (in C)?

心已入冬 提交于 2019-12-31 07:00:24

问题


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?


回答1:


fputs is not inherently dangerous. Of course without example code its hard to say what was causing the problem you were seeing.




回答2:


fputs() is not a "dangerous" function (unlike gets(), 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.



来源:https://stackoverflow.com/questions/5930736/fputs-puts-dangerous-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!