nein, strtok ermittelt eine gefundene Speicheradresse eines cstrings (edit: ) vor/bis zur ersten angegebenen delimiter-Bruchstelle,
und der Ausgangs-cstring wird entsprechend heruntergekürzt (der Rest-cstring hinter dem 1. delimiter):
char * strtok ( char * str, const char * delimiters );
Parameters
str
C string to truncate.
Notice that this string is modified by being broken into smaller strings (tokens).
Alternativelly, a null pointer may be specified, in which case the function continues scanning where a previous successful call to the function ended.
delimiters
C string containing the delimiter characters.
These can be different from one call to another.
Return Value
If a token is found, a pointer to the beginning of the token.
Otherwise, a null pointer.
A null pointer is always returned when the end of the string (i.e., a null character) is reached in the string being scanned.
ersetze mal im Beispiel printf durch Serial.println und main() durch void setup() und du wirst sehen, was passiert:
Example
http://www.cplusplus.com/reference/cstring/strtok/
Code:
/* strtok example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string "%s" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}
Output:
Code:
Splitting string "- This, a sample string." into tokens:
This
a
sample
string
Lesezeichen