strncpy function

# strtok function

All the books that I have read, say that strtok will break a string into tokens. This is true, but a more obvious explanation is, that it will break a string into words.

    Library:   string.h

    Prototype: char * strtok(char *s, const char *delim);

    Syntax:	   char string []="abc def ghi";
    	   char * word;

    	   word=strtok(string, " ");
    	   word=strtok(NULL, " ");

strtok requires a string and the word delimiters, for example:

    	   word = strtok(string, " ");
    	                   A      A
    	                   |      |
    	                   |	  -------  Delimiters.
    	                   |
    	                   --------------  String to break up.

After the first call to strtok, word will point to abc on the second call, word will point to def

## Notes:

- strtok will alter the I/P string by placing NULLS at the delimiter positions. A good habit is to copy the string to a tempary string and use the copy in the strtok call.

- More than one delimiter can be specified. So you could code:

      	word = strtok(string, " \t;:,");

- You do not have to include \0 or NULL

## Examples:

Example program.

## See also:

strcpy
strncpy

Top | Master Index | Keywords | Functions