第1个回答 2007-06-13
#include<stdio.h>
#include<string.h>
#define MAX 100
#define LETTER 1
#define NUMBER 2
#define OTHER 3
int count(char c[], int flag)
{
int i, l=0, n=0, o=0;
for(i=0;c[i]!='\0';i++)
if(c[i]>='0'&&c[i]<='9')
n++;
else if((c[i]>='a'&&c[i]<='z')||(c[i]>='A'&&c[i]<='Z'))
l++;
else
o++;
if(flag==LETTER)
return l;
if(flag==NUMBER)
return n;
if(flag==OTHER)
return o;
}
void main()
{
char c[MAX];
printf ("input string: ");
gets (c);
printf ("\nThere are %d letters.", count(c,LETTER));
printf ("\nThere are %d numbers.", count(c,NUMBER));
printf ("\nThere are %d other characters.", count(c,OTHER));
}