cnt[str[i]-'0']++;で
なぜ-'0'をしているのでしょうか
-'0'をしても値は変わらないですよね
分かる方教えてください
void str_dcount(const char str[],int cnt[]) { unsigned i=0; while (str[i]){ if(str[i]>='0' && str[i]<='9') cnt[str[i]-'0']++; i++; } } int main(void) { int i; int dcnt[10]={0}; char str[100]; printf("type strings:" ); scanf("%s",str); str_dcount(str,dcnt); puts("how many time did numbers apear?"); for(i=0;i<10;i++) printf(" '%d':%d\n",i,dcnt[i] ); return 0; } コード
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/09/01 15:38