Thread-safe extraction of tokens within a character array.
#include <extras/extras_string.h> char *strtok_r(char *str, const char *sep, char** tmp);
Parameter
str
A pointer to a character string to separate into tokens.
sep
A pointer to a character string containing separator characters.
tmp
A pointer to a character pointer.
This function performs a thread-safe operation of its counterpart, strtok(). Unlike strtok(), this function takes an extra argument, tmp, which the function uses to store its progress.
This facility is not specified in the ISO/IEC standards. It is an EWL extension of the standard libraries.
This facility may not be available on some configurations of the EWL.
#include <extras/extras_string.h> #include <stdio.h> int main(void) { char s1[] = "(a+b)*(c+d)"; char s2[] = "(e*f)+(g*h)"; char *token; char *separator = "()+*"; char *tmp1; char *tmp2; /* First calls to strtok_r(). */ token = strtok_r(s1, separator, &tmp1); puts(token); token = strtok_r(s2, separator, &tmp2); puts(token); /* Subsequent calls to strtok_r(). */ token = strtok_r(NULL, separator, &tmp1); puts(token); token = strtok_r(NULL, separator, &tmp2); puts(token); return 0; } Output: a e b f