Just change
while (*pStart != delim)
to this line
while (*pStart != '\0' && strchr(" \t\n", *pStart) == NULL)
The standard strchr function (declared in the string.h header) looks for a character (specified as the second argument) in the C-string (given as the first argument) and returns a pointer to the string from the position where this character is first. So strchr(" \t\n", *pStart) == NULL means that the current character ( *pStart ) was not found in the string " \t\n" , and this is not a separator! (Change this delimiter string " \t\n" to, of course, adapt it to your needs.)
This solution is a short and simple way to check whether a character is set in a set (usually small) of specified interesting characters. And it uses a standard feature.
By the way, you can do this using not only a C-string, but also std::string . All you need to do is declare const std::string to be " \t\n" -like, and then replace strchr with the find method of the declared separator string.
source share