#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 发布
本文介绍了一个使用C语言编写的程序,该程序可以统计输入字符串中的字母、数字和其他字符的数量。通过宏定义设置字符串的最大长度,并定义了计数变量。程序包含一个函数f,用于遍历字符串并进行分类计数。
2377

被折叠的 条评论
为什么被折叠?



