2

I need in my program to call strtok twice, one inside the other. The problem I've got is that the first strtok cannot resume the loop after executing the inside strtok and it loses the pointer of the first char.

To explain more here is an example:

main :

 tokens = strtok (stmt, ":");
        while (tokens != NULL) {
            convert_field(tokens);
            tokens = strtok (NULL, ":");
        }

in the convert_field function I do

tokens = strtok (sub_stmt, ".->//");
        while (tokens != NULL) {
            convert_field(tokens);
            tokens = strtok (NULL, ".->//");
        }
4

1 回答 1

5

strtok is not reentrant (which means you cannot call the function again before it finishes its previous execution), you have to use strtok_r (which is reentrant) instead.

于 2012-04-20T10:47:41.710 回答