Hi.
sscanf(text, "%s %s", name, company);
parses 'ian mceknis'
but it also parses 'ian mceknis'
and so on. How can i make this to parse only the first one? It must contain only one space not more.
Thank you.
Hi.
sscanf(text, "%s %s", name, company);
parses 'ian mceknis'
but it also parses 'ian mceknis'
and so on. How can i make this to parse only the first one? It must contain only one space not more.
Thank you.
If you want it to reject the latter example, you'll have to roll your own function to find/reject multiple spaces.
But my guess is that what you really want to do is strip the extra spaces. See: http://stackoverflow.com/questions/122616/painless-way-to-trim-leading-trailing-whitespace-in-c
You can't do this using only sscanf()
, which has pretty basic functionality. If you really need to enforce this (do you?), regular expressions might be more suitable here.
According to sscanf definition, this is absolutely impossible. To get desired result, I would read the text variable manually, searching for two consequent whitespace characters. If found, replace the second whitespace character with 0 and then call sscanf.