C/C++ Arena

Step 6 of 10

Strings through pointers

Since strings are char arrays, char * is the usual way to walk through one:

for (const char *c = s; *c != '\0'; c++) {
    // *c is the current character
}

Your turn: write int count_char(const char *s, char ch) that returns how many times ch appears in s.

Previous: null Next: Pointers to pointers