strcspn Function

Another function which we could use to break up our string is strcspn. Instead of overwriting a delimiter with \0 and returning a pointer to the start of the next token, it simply returns the index of the next occurence of a "delimiter" in the string. The advantage for us is that we can still use arithmetic operations and a space as delimiters, but they won't be overwritten at any point, so we can still read what they are, whenever we choose to.

The arguments used for strcspn are identical to those for strtok, except that we do not feed in NULL pointers at any time. We must ourselves keep track of where we are up to in our string by means of a pointer. One slight difference is that strcspn has no concept of the end of a string, and so one must be sure to check for the final \0 to avoid running over the end of the string.