初学字符串的小白的第一问

这周初学字符串这一章,有问题要问,又要麻烦大家了.
#include
#include
#include
int main()
{int cnt;
char sentence;

while((sentence=getchar()) != ‘\n’){

if((sentence>='A'&&sentence<='Z')||(sentence>='a'&&sentence<='z')||(sentence>='0'&&sentence<='9'))
    cnt++;

1
2
}
printf("%d",cnt-48);
return 0;
}
为什么我这个统计字符串中数字和字母字符的程序输出却是包含了空格的数据,我不是if条件中判断了吗.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{int cnt = 0;
char sentence;

while((sentence=getchar()) != '\n'){
    if((sentence>='A'&&sentence<='Z')||(sentence>='a'&&sentence<='z')||(sentence>='0'&&sentence<='9'))
        cnt++;
}
printf("%d",cnt);
return 0;
}