@Arthur352 , I think the error is that the third argument should be the address of the pointer , and you have NULL.
I write in Linux, here instead of the Windows strtok_s()
there is a similar function strtok_r()
.
Here is an example with her.
avp@avp-ubu1:~/hashcode$ cat strtok.c #include <stdio.h> #include <stdlib.h> #include <string.h> int main (int ac, char *av[]) { char *token, *saveptr, *str = av[1] ? *(++av) : (char *)"xaxa xoxo xixi", *strd = strdup(str); const char *sep = av[1] ? av[1] : " "; int i = 0; str = strd; printf ("source: [%s] separators: [%s]\n", str, sep); while (token = strtok_r(str, sep, &saveptr)) { printf ("token[%d] : <%s>\n", i++, token); str = 0; } free(strd); return puts("End") == EOF; } avp@avp-ubu1:~/hashcode$ g++ strtok.c avp@avp-ubu1:~/hashcode$ ./a.out source: [xaxa xoxo xixi] separators: [ ] token[0] : <xaxa> token[1] : <xoxo> token[2] : <xixi> End avp@avp-ubu1:~/hashcode$ ./a.out " zqwe 223 , sy, ,sa,so , ," ", " source: [ zqwe 223 , sy, ,sa,so , ,] separators: [, ] token[0] : <zqwe> token[1] : <223> token[2] : <sy> token[3] : <sa> token[4] : <so> End avp@avp-ubu1:~/hashcode$ echo $? 0 avp@avp-ubu1:~/hashcode$
What is not clear, ask