Old said:
1 occurrence of 0 in the string.
Your version works for CHAR_MIN <= c <= CHAR_MAX.
It doesn't work when c equals zero.
Peter's version works for CHAR_MIN <= c <= UCHAR_MAX.
I don't see the point in searching for values
outside the range of char, in an array of char,
and neither does strchr.
I think it's more better to compare *s against
the value of c converted to type char,
as in the standard's description of strchr.
size_t str_ccnt(const char* s, int c)
{
size_t n = 0;
do {
if (*s == (char)c) {
n++;
}
} while(*s++ != '\0');
return n;
}
strcmp and strncmp are the only standard string functions
which are based on unsigned char interpretation of bytes.
All of the others, like strchr, are based on char values.
I think strccnt should be more like strchr, than like strcmp.