c sscanf with character delimiter

后端 未结 1 1320
南旧
南旧 2021-01-15 17:45

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



        
相关标签:
1条回答
  • 2021-01-15 17:56

    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.

    0 讨论(0)
提交回复
热议问题