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.  
  9. printf("文字列の入力:");
  10. scanf("%s",str);
  11. printf("gefeafa");
  12. printf("検索文字の入力:");
  13. scanf(" %c",&c);
  14. printf("f");
  15. count=str_count(str,c);
  16. printf("検索文字の数 %d:",count);
  17. }
  18. int str_count(char*str,int c){
  19.  
  20. int count=0;
  21. for(int i=0;i<100;i++){
  22. if(str[i]==c){
  23. count++;
  24. }
  25. }
  26.  
  27. return count;
  28. }
  29.  
Success #stdin #stdout 0.01s 5456KB
stdin
gefeafa
f
stdout
文字列の入力:gefeafa検索文字の入力:f検索文字の数 2: