puking


私信TA

用户名:puking

访问量:16101

签 名:

等  级
排  名 676
经  验 3786
参赛次数 0
文章发表 20
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:
#include <ctype.h>

1 字符测试函数

  1> 函数原型均为int isxxxx(int)

  2> 参数为int, 任何实参均被提升成整型

  3> 只能正确处理处于ascii[0, 127]之间的值

2 字符映射函数

  1> 函数原型为int toxxxx(int)

  2> 对参数进行检测, 若符合范围则转换, 否则不变

  int tolower(int); 'A'~'Z' ==>'a'~'z'

  int toupper(int); 'a'~'z' ==>'A'~'Z'

isalpha检查ch是否是字母;

isalnum检查ch是否是数字;

iscntrl检查ch是否控制字符(其ASCII码在0和0x1F之间,数值为 0-31);

ispunct 检查ch是否是标点字符(不包括空格),即除字母,数字和空格以外的所有可打印字符;

isdigit检查ch是否是数字(0-9);isgraph检查ch是否可显示字符(其ASCII码在ox21到ox7E之间),不包括空格;

islower是否小写字母(a-z)tolower将ch字符转换为小写字母;isupper,toupper;

isprint检查ch是否是可打印字符(包括空格),其ASCII码在ox20到ox7E之间;

注意事项:


注意局部变量要初始化,不然可能会引起++结果不对




参考代码:

#include <stdio.h>

#include <string.h>

#include <ctype.h>

int main()

{

char str[1024]={0};

gets(str);

int len=strlen(str);

int i,alpha=0,num=0,space=0,other=0;

for(i=0;i<len;i++){

if(isalpha(str[i]))

alpha++;

else if(isalnum(str[i]))

num++;

else if(isspace(str[i]))

space++;

else

other++;

}

printf("%d %d %d %d",alpha,space,num,other);

return 0;

}


 

0.0分

0 人评分

  评论区