源代码如下:
#include<stdio.h>
#include<string.h>
void main()
{
char str[20];
int num=0,letter=0,other=0;
int i=0;
scanf("%s",str);
for(i=0; i<strlen(str); i++)
{
if(str[i]>='0'&&str[i]<='9') num++;
else if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z') letter++;
else other++;
}
printf("numbers: %d\nletters: %d\nothers: %d\n",num,letter,other);
}
扩展资料
1、统计文件的字符数、单词数以及总行数,包括每行的字符数和单词数。
2、空白字符(空格和tab缩进)不计入字符总数;单词以空格为分隔。不考虑一个单词在两行的情况,限制每行的字符数不能超过1000。