Unexpected behavior with `strtok` leading to incorrect tokenization of strings containing multiple delimiters
I'm having trouble with I've tried everything I can think of but I've been banging my head against this for hours....... I'm experiencing unexpected behavior when using `strtok` to tokenize a string containing multiple delimiters. The string I am working with is `"Hello,,World!! This is a test."`, and I intend to use both `,` and `!` as delimiters. However, the output does not match my expectations. After calling `strtok`, I am getting tokens that include empty strings between the consecutive delimiters, which I want to avoid. Here's the code I've written: ```c #include <stdio.h> #include <string.h> int main() { char str[] = "Hello,,World!! This is a test."; const char* delimiters = ",!"; char* token; // First call to strtok token = strtok(str, delimiters); while (token != NULL) { printf("%s\n", token); token = strtok(NULL, delimiters); } return 0; } ``` When I run this code, the output is: ``` Hello World This is a test. ``` As you can see, there are empty lines printed for the empty tokens, which is not the behavior I want. I've tried checking the return value of `strtok` and making sure I handle the results properly, but it seems like the empty tokens are simply part of how `strtok` processes the input. I would like to know if there is a way to filter out these empty tokens while still using `strtok`, or if I should consider using a different approach. Any insights would be greatly appreciated! I'm working on a mobile app that needs to handle this. What am I doing wrong? I'm using C stable in this project. Any examples would be super helpful. Could someone point me to the right documentation?