2026-08-20
count_char.c
#include <stddef.h>
size_t count_char(const char *s, char c) {
/* write this */
}
Implement count_char: return how many times c appears in the NUL-terminated string s.
Reference
size_t count_char(const char *s, char c) {
size_t n = 0;
for (; *s; s++) {
if (*s == c) n++;
}
return n;
}
Walk the string once, comparing each byte before the loop advances past it.