For the string returned by strtok
, does it have a \0
at the end?
Or does it not, like the strncpy
function?
I would check by copying the return value of strtok
to another string array with strcpy
, but then I wouldn't know if the appended \0
was the effect of strtok
or strcpy
(since strcpy
does add \0
).
edit: sorry, I can't "copy the return value to of strtok
to another string array with strcpy
".
strtok() returns a NULL pointer. The token ends with the first character contained in the string pointed to by string2. If such a character is not found, the token ends at the terminating NULL character. Subsequent calls to strtok() will return the NULL pointer.
When there are no tokens left to retrieve, strtok returns NULL, meaning that the string has been fully tokenized.
The C function strtok() is a string tokenization function that takes two arguments: an initial string to be parsed and a const -qualified character delimiter. It returns a pointer to the first character of a token or to a null pointer if there is no token.
Each call to strtok() returns a pointer to a null-terminated string containing the next token. This string does not include the delimiting byte.
From cplusplus.com
This end of the token is automatically replaced by a null-character, and the beginning of the token is returned by the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With