fork download
  1. #include <stdio.h>
  2. int str_count(char *str, int c);
  3.  
  4. int main(void) {
  5. char str[100];
  6. char c;
  7. int count=0;
  8. printf("文字列の入力:"); scanf("%s",str);
  9. printf("検索文字の入力:"); scanf(" %c",&c);
  10. count=str_count(str,c);
  11. printf("検索文字の数:%d\n",count);
  12. return 0;
  13. }
  14.  
  15. int str_count(char *str, int c){
  16. int count=0;
  17. while(*str){
  18. if(*str==c){
  19. count++;
  20. }str++;
  21. }
  22. return count;
  23. }
  24.  
Success #stdin #stdout 0s 5516KB
stdin
ghgygygy
g
stdout
文字列の入力:検索文字の入力:検索文字の数:4