#include <stdio.h>
int str_chnum(const char *str, int c)
{
unsigned count = 0;
while(*str){
if(*str == c) count++;
str++;
}
return count;
}
char *str_chr(const char *str, int c)
{
char *p = NULL;
while(*str){
if(*str == c){
p = (char *)str;
break;
}
str++;
}
return p;
}
int main(void)
{
char str[100];
char ch;
printf("文字列を入力してください:");
scanf("%s", str);
printf("検索する文字を入力してください:");
scanf("%c", &ch);
printf("入力された文字のアドレスは%p\n", str_chr(str, ch) );
printf("入力された文字は%dこあります\n", str_chnum(str, ch) );
return 0;
}
40行目のscanf文が実行されません。
1回めに出てくるscanf文は実行されるのになぜ2回めの方だけが実行されないのでしょうか?