samedi 16 janvier 2021

How can i solve this strtok null-ing problem? [duplicate]

Can someone explain me why the strtok used in a if clause modify the further uses of strtok?

I have the following code:

  char* caca = new char[100];
    const char* cacatok = new char[100];
    strcpy(caca, "1, muntenia[");
    cacatok = strtok(caca, " ");
    cout << cacatok;
    /*(if (strtok(NULL, "qwertyuioplkjhgfdsazxcvbnm") != NULL)
        cout << "OK";*/
    cacatok = strtok(NULL, " ");//after the if clasue, this line make cacatok NULL instead of "muntenia[". If i don t use that if clause, it works just fine.
    cout << cacatok;

Can someone explain to me how can i very that without ruining the following strtoks? I tried using functions to verify, copies, but i still get that NULL.

Aucun commentaire:

Enregistrer un commentaire