Онлайн компилятор C

#include <stdio.h> void print_digit_count(char number[]) { int cnt[10] = {0}; for (int i = 0; number[i] != '0'; i++) int main() { int d = number[i] - '0'; cnt[d]++; } for (int i = 0; i <= 9; i++) { if (cnt[i] > 0) printf("%d %d\n", i, cnt[i]); } } return 0; }
The code attempts to count how many times each digit appears in a string, but it has a syntax error and a logic issue. The loop condition `number[i] != '0'` checks for the character '0' instead of the null terminator, and the function definition is broken by an unexpected `int main()` inside it.

- The loop condition `number[i] != '0'` should check for the end of the string, which is the null character `'\0'`, not the digit character `'0'`. Using `'0'` will stop the loop early if the string contains the digit zero.
- The function body is incorrectly structured: the `int main()` line appears inside the `print_digit_count` function, which is a syntax error. The function should have its own body without extra function definitions inside it.