69,382
社区成员
发帖
与我相关
我的任务
分享
#define BUFSIZE 27
int countAlpha[BUFSIZE];
void CalCount(char * p) {
int bLen = strlen(p);
int i;
memset((void *)countAlpha,0,BUFSIZE * sizeof(int));
for(i=0;i<bLen;i++) {
if((p[i]<='Z')&&(p[i]>='A'))
countAlpha[p[i]-'A'] ++;
else if((p[i]<='z')&&(p[i]>='a'))
countAlpha[p[i]-'a'] ++;
else
countAlpha[26] ++;
}
}
typedef struct
{
int AlphaNum;
int OtherNum;
}STU;
/********************************************************************
* 函数名称: fun *
* 参 数: char *p *
* 返回类型: STU *
* 函数功能: 实现任意字符串中字母(大小写)和非字母的字符个数统计 *
* 编写日期: 200711.17 *
* 修改日期: 无 *
* 其 他: 需包含头文件string.h,ctype.h,及STU类型定义前提下 *
********************************************************************/
STU fun(char *p)
{
STU stu = {0, 0};
int len = strlen(p);
while((len--) > 0)
{
if(isalpha(*p))
{
stu.AlphaNum++;
}
else
{
stu.OtherNum++;
}
p++;
}
return(stu);
}