Reputation: 3162
I use the following to split my strings into usable information
sscanf(last, "%*[^:]:%*[^:]:%*[^:]:%127[^:]:", field_x);
which would grab the fourth field of a string separated by colons, but now I need to use it to split a string separated by spaces, but I have no clue how to do it as doing throwing " "'s in place of the colons would not work, neither did replacing it with a \t work either, if someone could point me in the right direction for this I would really appreciate it (also I saw an example for strtok, but feel this type of string splitter is much easier to control in this instance) thanks!
Upvotes: 0
Views: 84
Reputation: 28545
Contrary to what you believe,
sscanf(last, "%*[^ ] %*[^ ] %*[^ ] %127[^ ] ", field_x);
indeed does what you want
Upvotes: 2