2

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?

user1190650
  • 3,207
  • 6
  • 27
  • 34

1 Answers1

4

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.

cnicutar
  • 178,505
  • 25
  • 365
  • 392