判断一个字符是否是数字、还是大小写字母

//方法一:

int main()

{

printf("please input one character:\n");

        input=getchar();
        while(input==10)   //如果输入的是回车键,则再次输入;因为回车键也是一个字符;
        {
                printf("please input again:\n");
                input=getchar();
        }
        if(input <= 32)
                printf("You have input a control  character!!\n");
        else if(input >= 48 && input <= 57)    //数字;
        {
                for( i=48;i<58;i++)
                {
                        if(input==i)
                                break;
                }
                printf("You put a number,ranging from 0--9!\n The number is %d!\n ",i);
        }
        else if(input >=65 && input <=90 )  //大写字母;
        {
                for( i=65; i<=90; i++)
                {
                        if(input==i)
                                break;
                }
                printf("You have put a uppercase! Ranging from A--Z!\nThe number is %d!\n",i);
        }
        else if(input >=97 && input <=122)   //小写字母
        {
                for( i=97;i<=122;i++)
                {
                        if(i==input)
                                break;
                }
                printf("You have input a lowercase! Ranging from a--z!\nThe number is %d\n",i);
        }
        else  
                printf("You have input a other character!\n");

        }


方法二:用isalnum()函数来判断输入的字符是否是数字还是字符;

        char * character="JFKSKS%%$$#$(()(^!!!kjhefwew!!!";
        printf("The date are:JFKSKS%%$$#$(()(^!!!kjhefwew!!!");
        printf("The date are:\n");
        char *strs=malloc(sizeof(character));
        strcpy(strs,character);
        for(i=0;strs[i]!=0;i++)
                if(isalnum(strs[i]))
                        printf("%c is a character!!\n",strs[i]);


  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值