fork download
  1. #include <stdio.h>
  2.  
  3. int str_countchar(char *str, int c);
  4.  
  5. int main(void)
  6. {
  7. int a;
  8. char str[100];
  9. char c;
  10. int count=0;
  11.  
  12. printf("文字列の入力:");
  13. scanf("%s",str);
  14. printf("検索文字の入力:");
  15. scanf(" %c",&c);
  16.  
  17. a=str_countchar(str, c);
  18. printf("検索文字の数:%d\n",a);
  19.  
  20. return 0;
  21. }
  22.  
  23. int str_countchar(char *str, int c)
  24. {
  25. int count=0;
  26. while(*str != NULL){
  27. if(*str==c)
  28. count++;
  29. str++;
  30. }
  31. return count;
  32. }
  33.  
  34.  
Success #stdin #stdout 0s 5460KB
stdin
abcd
a
stdout
文字列の入力:検索文字の入力:検索文字の数:1