c - Strtok and its input -


i using strtok out of while loop split input in 3 strings, eg:
input="command path 'you beautiful'" split into:

tok1="command"
tok2="path"
tok3="'you beautiful'"

i can't use strtok 3 times in row because tok3 "'you".
question is, happens initial variable input when use strtok?
after first call of strtok input "path 'you beautiful'", , after second 1 "'you beautiful", progessively reducing initial string run strtok.
possibile? if not, how can it?

strtok behaviour defined in standard(http://pubs.opengroup.org/onlinepubs/009695399/functions/strtok.html) follows:

a sequence of calls strtok() breaks string pointed s1 sequence of tokens, each of delimited byte string pointed s2. first call in sequence has s1 first argument, , followed calls null pointer first argument. separator string pointed s2 may different call call.

the first call in sequence searches string pointed s1 first byte not contained in current separator string pointed s2. if no such byte found, there no tokens in string pointed s1 , strtok() shall return null pointer. if such byte found, start of first token.

the strtok() function searches there byte contained in current separator string. if no such byte found, current token extends end of string pointed s1, , subsequent searches token shall return null pointer. if such byte found, overwritten null byte, terminates current token. strtok() function saves pointer following byte, next search token shall start.

each subsequent call, null pointer value of first argument, starts searching saved pointer , behaves described above.

this means call strtok 2 times, , determine location past \0 of second substring third part want.

however, doesn't seem reasonable way of doing this. inflexible, both in dealing error (like when third substring empty), , potential future expansions. furthermore, because of design of strtok interface, using not thread-safe @ all.

it better idea hand-code small lexer/parser want, or use tool designed building lexers (and parsers if needed). have had experiences flex purpose, there other options.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -