Just walk over the chars and check for whitespace (e.g. using the isspace
function).
Alternatively, convert the char*
to a std::string
and use string functions, i.e. find_first_not_of
. For example, using the “conventional” whitespace characters in pre-Unicode encodings:
bool is_all_spaces(char const* text, unsigned len) {
string str(text, len);
return str.find_first_not_of(" \t\r\n\v\f") == string::npos;
}
A more fancy whitespace recognition would cope with arbitrary text encodings / locales. For that reason, using isspace
is probably superior to the find_first_not_of
approach.
In either case, using memcmp
in C++ is ill-advised anyway and you should generally prefer C++ strings to C-style char arrays.