06.08.2013 Views

pSOSystem System Calls - Read

pSOSystem System Calls - Read

pSOSystem System Calls - Read

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

strtok pREPC+ <strong>System</strong> <strong>Calls</strong><br />

strtok Searches a string for tokens.<br />

#include <br />

char *strtok(<br />

char *s1, /* search string */<br />

const char *s2 /* delimiter(s) */<br />

)<br />

Description<br />

Arguments<br />

A series of calls to the strtok() function breaks a string (s1) into a sequence of<br />

tokens, each of which is delimited by a character in a second string (s2). A token is<br />

a sequence of one or more characters. The first call to strtok() has s1 as its first<br />

argument, and is followed by calls with a null pointer as their first argument.<br />

On the first call to strtok(), s1 is passed as a pointer to the string to be searched,<br />

and s2 is passed as a pointer to the string that contains the delimiters. The first call<br />

searches for the first character in s1 that is not found in the delimiter set. If such a<br />

character is found, it is the start of the first token. If the first call fails to find a<br />

character that is not a delimiter, there are no tokens, and a null pointer is returned.<br />

The function then continues the search of s1 for a character that is contained in the<br />

delimiter set. If no such character is located, the current token extends to the end of<br />

s1, and subsequent calls to the function return a null pointer. If a delimiter is<br />

located, a null character that terminates the current token overwrites the delimiter.<br />

The function saves the pointer to the character that follows. This is where the next<br />

search for a token starts.<br />

In subsequent calls, the first argument should be a null pointer. The search for the<br />

next token begins from the saved pointer and behaves as described in the preceding<br />

paragraph.<br />

The search string s2 can be changed between calls. This allows strtok() to<br />

continue to parse the string with a different set of delimiters.<br />

s1 Points to the string to be searched.<br />

s2 Points to the string containing token delimiters.<br />

3-166 <strong>pSO<strong>System</strong></strong> <strong>System</strong> <strong>Calls</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!