今勉強している内容で、参考書の通り入力してもうまくいきません。
数字文字の出現回数を数えるプログラムなのですが、実行結果に数が反映されません。
何が原因がわかる方がいらっしゃればご教授願いたいです。
--以下、実際のプログラム-------------
#include<stdio.h>
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(">>");
scanf_s("%s", str);
str_dcount(str, dcnt);
printf(">>>>>\n");
for (i = 0; i < 10; i++)
printf("'%d':%d\n", i, dcnt[i]);
return(0);
}
*添付画像は参考書の内容の写真です
前の質問で、scanf_s で文字列を読み込むときには、サイズの指定が必要だ、って話だったじゃない。
scanf_s("%s", str, 100);
# 間違えたぼくが言うのも、なんだけどさ (^^;
その通りでした!!
2014/07/28 15:10:28何度も同じ間違いをしてすいません;;
前回に引き続きどうもありがとうございます。