Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
size_t count_whitespace(const char *s) {
  const char *t = s;
  while(isspace(*t))  /* possibly *t < 0 */
    ++t;
  return t - s;
}

Compliant Solution 1

Pass character strings around explicitly using unsigned characters.

Code Block

size_t count_whitespace(const unsigned *s) {
  const char *t = s;
  while(isspace((unsigned char)*t))
    ++t;
  return t - s;
}

This approach is inconvenient when you nned to interwork with other functions that haven't been designed with this approach in mind, for exampl,e the string handling functions found in the standard library.

Compliant Solution 2

This compliant solution uses an explicit cast.

...