如何将\n作为计数项而依然用回车表示输入结束?

以下程序统计输入的一行字符中字母、数字、空格、其它字符的个数(行末以换行符结束,最后的换行符不统计在内)。例如,输入的一行字符为aB 3*则字母有2个,数字有1个,空格有1个,其它字符有1个。


#include <stdio.h>
int main()
{
    int letters, digits, spaces, others;
    letters=digits=spaces=others=0;
    char ch;
    while( scanf("%c",&ch),    )//不知道咋填了
    {
        if( ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
            letters++;
        else if( ch>='0'&&ch<='9')
            digits++;
        else if( ch==' ')
            spaces++;
        else
            others++;
    }
    printf("字母、数字、空格、其它字符分别有:%d %d %d %d 个\n",letters,digits,spaces,others);
}
while((ch=getchar())!='\n')

第8行这么填:while( scanf("%c",&ch), ch != '\n')