- #include "stdio.h"
- #define M 1000 // 宏定义字节最大长度
- int character = 0, num = 0, other = 0;
- int f(char *x)
- {
- int i = 0;
- for ( i = 0; *(x+i) != ' '; i++)
- {
- if (( *( x + i ) >= 'a' && *( x + i) <= 'z') || (*( x + i ) >= 'A' && *( x + i) <= 'Z'))//字母个数
- character++;
- else if ( *( x + i ) >= '0' && *( x + i) <= '9')//数字个数
- num++;
- else
- other++;//其它字符个数
- }
- printf ("The character is:%d ", character );
- printf ("The number is:%d ", num );
- printf ("Other is:%d ", other );
- return ( word, num, other);
- }
- main()
- {
- char ch[M];
- printf ("请输入你要求的字符串 ");
- gets(ch);//字符串的输入
- f(ch);//函数的调用
- }