且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从输出中删除不需要的字符

更新时间:2022-06-23 22:21:40

strcat 连接字符串。在你的代码中,它将一个可能有效的字符串( inputstring )连接到垃圾( copystring 未初始化)。

如果您只需要输入字符串的副本,请使用 strncpy 而不是 strcat

请注意:永远不要使用获取。改为使用 fgets stdin
strcat concatenates strings. In your code it concatenates a possibly valid string (inputstring) to garbage (copystring is not initialized).
If you just need a copy of the input string, use strncpy instead of strcat.
Please note: never ever use gets. Use fgets with stdin instead.