Returns the number of times a character occurs in a string for a null terminated string.
| 218 | // Returns the number of times a character occurs in a string for a null |
| 219 | // terminated string. |
| 220 | inline ptrdiff_t strcount(const char* buf, char c) { |
| 221 | if (buf == NULL) |
| 222 | return 0; |
| 223 | ptrdiff_t num = 0; |
| 224 | for (const char* bp = buf; *bp != '\0'; bp++) { |
| 225 | if (*bp == c) |
| 226 | num++; |
| 227 | } |
| 228 | return num; |
| 229 | } |
| 230 | // Returns the number of times a character occurs in a string for a string |
| 231 | // defined by a pointer to the first character and a pointer just past the last |
| 232 | // character. |