题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#include "stdio.h" #include "string.h" // #define diff int main(){ int count = 0; char str[1010] = {0}; fgets(str,sizeof(str),stdin);
// printf("%c",str[0]); char C = {0}; // printf("请输入一个字符:"); scanf("%c",&C); C = tolower(C); for(int i = 0; i<strlen(str);i++){ str[i] = tolower(str[i]); if(str[i] == C) count++; } printf("%d",count);
}