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