当前位置: 代码迷 >> C语言 >> 统计其中的字母、数字和其他字符的数目
  详细解决方案

统计其中的字母、数字和其他字符的数目

热度:163   发布时间:2007-07-04 22:55:48.0
统计其中的字母、数字和其他字符的数目
35. 编程序从键盘上输入一个字符串(长度小于或等于80),分别统计其中的字母、数字和其他字符的数目。本题要求用指向数组首地址的指针变量来处理字符串中的字符。
搜索更多相关的解决方案: 字符  字母  数字  统计  变量  

----------------解决方案--------------------------------------------------------
历遍字符串,比较字符的ASK码
----------------解决方案--------------------------------------------------------

额、、、、、、、、、、可以说具体点吗?具体怎么编?谢谢~!


----------------解决方案--------------------------------------------------------
int main()
{
char str[100];
int i,a,len,t=0,k=0,m=0;

printf("imput:");
scanf("%s",str);

len=strlen(str);
for(i=0;i<len;i++)
{
a=str[i];
if(a>=48 && a<=57)
t++;
else if((a>=68 && a<=90) || (a>=97 && a<=122))
k++;
else
m++;
}

printf("number:%d.string:%d,other:%d\n",t,k,m);
}
----------------解决方案--------------------------------------------------------

指针指针还没熟悉:
#include"stdio.h"
int main(void)
{
char s[80],*p;
int m=0,n=0,j=0,i=0;
p=s;
while((s[i++]=getchar())!='\n');
while(*p!=NULL&&*p!='\n'){
if(*p>='a'&&*p<='z'||*p>='A'&&*p<='Z')
++m;
else if(*p>='0'&&*p<='9')
++n;
else
++j;
p++;}
printf("%i %i %i",m,n,j);
getch();
return 0;
}


----------------解决方案--------------------------------------------------------
ctype.h的头文件包括了:
isalpha() 判断字母
isdigit() 判断数字
剩下的就是其他符号了萨~~

----------------解决方案--------------------------------------------------------
  相关解决方案