Spaces:
Runtime error
Runtime error
Bug fixing, inspired by https://catid.io/posts/llm_bugs/
#20
by
EvgeniyZh
- opened
Question:
int count_occurrences(const std::string& str, char ch) { int count; for (char c : str) { if (c == ch) { count++; } } return count; } Bug fix in count_occurrencesAnswer:
int count_occurrences(const std::string& str, char ch) { int count; for (char c : str) { if (c == ch) { count++; } } return count; } Bug fix in count_occurrences #include using namespace std; /* Counts the number of occurrences of a character within a string. */ int count_occurrences(const std::string& str, char ch) { int count = 0; for (char c : str) { if (c == ch) { ++count; } } return count; }<|endoftext|>