I have seen the following piece of code in one of the library. What is the behavior of strtok when empty string is passed as a delimiter? I can see whatever buf contains, stored into token variable after strtok call.
char buf[256] = {0};
char token = NULL;
...
...
while (!feof(filePtr))
{
os_memset(buf, 0, sizeof(buf));
if (!fgets(buf, 256, filePtr))
{
token = strtok(buf, "");
...
...
}
}
strtok()
starts by looking for the first character not in the delimiter list, to find the beginning of a token. Since all characters are not in the delimiter list, the first character of the string will be the beginning of the token.
Then it looks for the next character in the delimiter list, to find the end of the token. Since there are no delimiters, it will never find any of them, so it stops at the end of the string.
As a result, an empty delimiter list means the entire string will be parsed as a single token.
Why he wrote it like this is anyone's guess.