c语言问题:求一句代码中的字母数,空格数,和标点符号数?

来源:百度知道 编辑:UC知道 时间:2024/06/05 14:47:20
刚学c语言,很多问题都不懂,请大家多指点!

#include <stdio.h>
int main()
{
char ch[60]="I love the beautiful life. Enjoy it, my friends!";
/*there are 8 blanks,1 comma,1 dot,1 exclamatory point*/
int letter=0,punctuation=0,blank=0;
for(int i=0;ch[i]!='\n';i++)
{
if( (ch[i]>32 && ch[i]<48 )||
(ch[i]>57 && ch[i]<65)||
(ch[i]>90 && ch[i]<97))
punctuation++;
if( ch[i]==' ')
blank++;
if( ch[i]>='a' && ch[i]<='z' ||
ch[i]>='A' && ch[i]<='Z')
letter++;
}
printf("%s\n",ch);
printf("letter=%d,blank=%d,puctuation=%d\n",letter,blank,punctuation);
}

han 3