将字符读入时转为小写,遍历字符串时,将每一个字符也转为小写比较。

#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);
    
    
}

求指点,为啥我开辟1000大小的数组空间时,有个1000字符的案例,显示读入的字符并不是所给的字符?