the following code will break down the string command using space i.e " " and a full stop i.e. "." What if i want to break down command using the occurrence of both the space and full stop (at the same time) and not each by themselves e.g. a command like: 'hello .how are you' will be broken into the pieces (ignoring the quotes) [hello] [how are you today]
char *token2 = strtok(command, " .");
You can do it pretty easily with
strstr
:This is pretty much exactly the same as the implementation of
strtok
, just callingstrstr
andstrlen
instead ofstrcspn
andstrspn
. It also might return empty tokens (if there are two consecutive delimiters or a delimiter at either end); you can arrange to ignore those if you would prefer.Your best bet might just be to crawl your input with
strstr
, which finds occurrences of a substring, and manually tokenize on those.It's a common question you ask, but I've yet to see a particularly elegant solution. The above is straightforward and workable, however.