What\'s the difference between strtok
and strtok_r
in C
and when are we supposed to use which?
strtok
is equivalent to (and often defined as):
char *strtok(char *str, const char *delim) {
static char *save;
return strtok_r(str, delim, &save);
}
in general, you should use strtok_r
directly rather than strtok
, unless you need to make your code portable to pre-POSIX-2001 systems that only support strtok