strspn Function

In fact we will use a close relative of strcspn called strspn. It works identically except that it returns the index of the first character which does not occur in our "delimiter" list. We will use the numerals 0 to 9 for our list of characters, so the function will tell us the next position within the string which is not a numeral. It is useful to do things this way around, since it acts as a check on what the user has entered. Whenever we get to a character which is not a numeral, if it is an arithmetic operator, we will process it, however, if it is something different (other than an end of string or carriage return) then we can generate an error.

In order to make use of the strspn function, we will keep a pointer to where we are up to in the string. In fact it is this pointer that we will feed into strspn as its first argument. After all, it doesn't know where our original string started, so by feeding this pointer in, it just takes that location within the string as the start and looks for the next non-numeral.

Of course this method of processing will only be useful if we are already pointing to the start of a number within the string, i.e. if the pointer that keeps track of where we are, is currently pointing to the first digit of a number within the string.