strtok, _fstrtok
Searches one string for tokens, which are separated by delimiters defined in a second string.
Defined in header <string.h>
Syntax
#include <string.h>
Near version: char *strtok(char *sl, const char *s2);
Far version: char far * far _fstrtok(char far *sl, const char far *s2)-
Portability
| DOS | UNIX | Windows | ANSI C | C++ only | |
|---|---|---|---|---|---|
| Near version | ■ | ■ | ■ | ■ | |
| Far versior^ | ■ | ■ |
Remarks
strtok considers the string si to consist of a sequence of zero or more text tokens, separated by spans of one or more characters from the separator string s2.
The first call to strtok returns a pointer to the first character of the first token in si and writes a null character into si immediately following the returned token. Subsequent calls with null for the first argument will work through the string si in this way, until no tokens remain.
The separator string, s2, can be different from call to call.
Return value
strtok returns a pointer to the token found in s2. A null pointer is returned when there are no more tokens.
Example
include <string.h>
#include <stdio.h>
int main(void)
{
char input[16] = "abc,d";
char *p;
/* strtok places a NULL terminator
in front of the token, if found */
p = strtok(input, ",");
if (p) printf("%s\n", p);
/* a second call to strtok using a NULL as the first parameter returns a
pointer to the character following the token */
p = strtok(NULL, ",");
if (p) printf("%s\n", p);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `strtok, fstrtok` read as `strtok, _fstrtok`
Stable link: /3.1/string.h/strtok/
· short form /3.1/strtok/