如何识别C中整数输入的具体数字?

zxc*_*xcv 0 c string function

我需要得到包含数字1的数字位数.我知道在java中我可以将输入作为a String和use使用charAt,但我知道C中没有隐式的String函数.我怎样才能实现这一点?

Aar*_*paa 6

分裂和模数是你的朋友.

#include "stdio.h"

int main(){
    int digits[] = {0,0,0,0,0,0,0,0,0,0};
    int i = 11031;

    while(i > 0){
        digits[i % 10]++;
        i = i / 10;
    }

    printf("There are %d ones.\n", digits[1]);
}
Run Code Online (Sandbox Code Playgroud)