Question

Why is the strtok(char* str, const char* delimiters) function non-reentrant?

Why is the strtok(char* str, const char* delimiters) function non-reentrant?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The strtok function maintains a internal static pointer to keep hold of the passed string. For example,if our string is "hello people !!", and we tokenize it by a separator " ", we use

char t*=strtok(string," ").

now, the string is searched,and as soon as first " " is found, it returns the token.

To continue searching,it then passes a null in place of string, as it already is keeping a static pointer to the string. This is why it is non-reentrant. As soon as a new pointer is passed to it, it forgets all the earlier string.

Add a comment
Know the answer?
Add Answer to:
Why is the strtok(char* str, const char* delimiters) function non-reentrant?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT