scanf on non-STDIN input

二次信任 提交于 2019-12-11 11:59:57

问题


Is it possible to run scanf on input that it is not STDIN? What I mean is if I have a string="hello 1 2 3", can I run scanf on it to extract the string and three integers?

Is there another function that can do this?


回答1:


sscanf on a string (info here)

fscanf on a file (info here)

similarly sprintf and fprintf to write to a string/file.




回答2:


If you have a string, sscanf would be more appropriate. The title of your question implies reading from a different stream, for which there are other similar functions (see fscanf).



来源:https://stackoverflow.com/questions/6922253/scanf-on-non-stdin-input

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