cybersecurity · beginner · ~15 min
Tally format-control characters.
Count the % characters in a string — a quick risk indicator for text about to be used as a printf format.
Implement int count_percent(const char *s) that returns how many % characters appear in s.
s: a NUL-terminated string the grader passes.Returns int: the total number of % characters (each one counts, including those in %%).
count_percent("%d and %s") -> 2
count_percent("100%%") -> 2 (both percent signs count)
count_percent("clean") -> 0
% returns 0.% is counted, escaped or not.A NUL-terminated string s.
An int: the count of % characters in s.
Count every %, including those in %%.
int count_percent(const char *s) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.