Reputation: 9733
my string is:
He is a "funny" guy
How can I extract that using strtok_r
?
strtok_r(str, "\"", &last_pointer);
Is this a correct way of doing it? will the statement above skip first "
?
Upvotes: 1
Views: 423
Reputation: 108978
My documentation for strtok_r
says
char *strtok_r(char *str, const char *delim, char **saveptr);
On the first call to
strtok_r()
,str
should point to the string to be parsed, and the value ofsaveptr
is ignored. In subsequent calls,str
should beNULL
, andsaveptr
should be unchanged since the previous call.
So you should call it first with
strtok_r(str, "\"", &last_pointer);
and afterwards with
strtok_r(NULL, "\"", &last_pointer);
Upvotes: 1
Reputation: 3990
this POSIX function will skip all leading '\"' not the first. call strtok_r a second time with NULL as first parameter and have fun.
Upvotes: 1