lacrosse1991
lacrosse1991

Reputation: 3162

How can I use a space as a delimiter for this code

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

Answers (1)

Pavan Manjunath
Pavan Manjunath

Reputation: 28545

Contrary to what you believe,

sscanf(last, "%*[^ ] %*[^ ] %*[^ ] %127[^ ] ", field_x);

indeed does what you want

Upvotes: 2

Related Questions