#include<stdio.h>
#define N 999
int main(void)
{
char t, ch;
char str[N];
int i=0,count=0;
int repeat,x;
scanf("%d", &repeat);
getchar();
for(x= 1;x<= repeat;x++){
i=0;
while((str[i] = getchar( )) != '\n')
i++;
str[i] = '\0';
t= getchar();
getchar();
count=0;
for(i=0;str[i] !=0;i++){
if(str[i]==t) count++;
}
printf("count = %d\n", count);
}
}
❤一定要记住i=0和count=0的说明。最后一个for语句 str[i]!=0x等价于str[i] !='\0'。