int len;
int loop;
int count;
char str[300];
while(1)
{
gets(str);
len = strlen(str);
if(len == 0)
{
break;
}
count = 0;
for(loop = 0; loop < len; loop++)
{
if((str[loop] >= '0') && (str[loop] <= '9'))
{
count++;
}
if((str[loop] >= 'A') && (str[loop] <= 'Z'))
{
count++;
}
if((str[loop] >= 'a') && (str[loop] <= 'z'))
{
count++;
}
}
printf("%d\n", count);
}
可以一个个读取
if ( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9') ){
num++;
}
else if( ch=='\n' ){
printf("%d\n", num);
}
void staticsChar()
{
int nInput,nCount=0;
char ch[NUM];
while (1) {
nInput=getchar();
if(nInput=='\n' || nCount>=NUM){
break;
}
ch[nCount++]=nInput;
}
int a=0;int b=0;int c=0;int d=0;int e=0;int other=0;
for(int j=0;j
char temp=ch[j];
if(temp=='a'){a++;}
else if(temp=='b'){b++;}
else if(temp=='c'){c++;}
else if(temp=='d'){d++;}
else if(temp=='e'){e++;}
else{other++;}
}
printf("a=%d,b=%d,c=%d,d=%d,e=%d,other=%d\n",a,b,c,d,e,other);
}
帮不了啦~这个是我大学学的最不好的一门语言啦~