Online Compiler C

#include <stdio.h> void print_digit_count(char number[]) { int count[10] = {0}; for (int i = 0; number[i] != '\0'; i++) { int digit = number[i] - '0'; count[digit]++; } for (int i = 0; i <= 9; i++) { if (count[i] > 0) { printf("%d %d/n", i, count[i]); } } } int main() { return 0; }
这段代码定义了一个函数 `print_digit_count`,它接收一个字符串(字符数组),统计其中每个数字字符('0'到'9')出现的次数,然后输出出现次数大于0的数字及其次数。但代码中存在一个关键问题:`main` 函数没有调用 `print_digit_count`,所以程序运行后什么也不会输出。

- 在 `printf` 中使用了 `/n` 而不是 `\n`,这会导致换行符无法正确输出,应该使用反斜杠 `\`。
- 函数 `print_digit_count` 没有在 `main` 中被调用,你需要添加一个测试用的字符串作为参数来调用它。