fflush(stdin) function does not work

半世苍凉 提交于 2019-11-26 23:16:44
templatetypedef

The fflush function does not flush data out of an input stream; it is instead used to push data buffered in an output stream to the destination. This is documented here. As seen in this earlier SO question, trying to use fflush(stdin) leads to undefined behavior, so it's best to avoid it.

If you want to eat the newline from the return character entered when the user finished typing in their character, instead consider the following:

scanf("%c\n", &sect_cat);

This will eat the newline rather than leaving it in stdin.

Hope this helps!

I think that you meant to write fflush(stdout) instead of fflush(stdin).

fflush should work with an output stream, see docs here

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