Why do we use NULL in strtok()?

strtok is part of the C library and what it does is splitting a C null-delimited string into tokens separated by any delimiter you specify.

The first call to strtok must pass the C string to tokenize, and subsequent calls must specify NULL as the first argument, which tells the function to continue tokenizing the string you passed in first.

The return value of the function returns a C string that is the current token retrieved. So first call –> first token, second call (with NULL specified) –> second token, and so on.

When there are no tokens left to retrieve, strtok returns NULL, meaning that the string has been fully tokenized.

Here’s the reference, with an example: http://www.cplusplus.com/reference/cstring/strtok/

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)