#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) != '\0'; 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\n", character );
printf ("The number is:%d\n", num );
printf ("Other is:%d\n", other );
return ( character, num, other);
}
main()
{
char ch[M];
printf ("请输入你要求的字符串\n");
gets(ch);//字符串的输入
f(ch);//函数的调用
}
定义指针函数,输入字符串求其中的字母、数字和其它字符的个数
最新推荐文章于 2024-01-09 14:52:22 发布