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