c sscanf with character delimiter

痴心易碎 提交于 2020-05-08 15:41:47

问题


I have an input string of the form

char *s = "one.two three"

and I want to separate it into 3 string variables. I'm doing

sscanf(s, "%s.%s %s", one, two, three);

but it's reading in "one.two" as the string for variable one. How do I handle the "." and the whitespace with sscanf?


回答1:


The %s specifier only stops for a space. Try something like:

sscanf(s, "%[^.].%s %s", one, two, three);

Interestingly, it's likely impossible to produce an acceptable input for "%s.%s %s" since %s only stops for a space yet a . must immediately follow it.



来源:https://stackoverflow.com/questions/12654599/c-sscanf-with-character-delimiter

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