C 标准库 - ctype.h之isalpha使用

isalpha

int isalpha ( int c );
  • Checks whether c is an alphabetic letter.
  • 检查给定字符是否字母字符,即是大写字母( ABCDEFGHIJKLMNOPQRSTUVWXYZ )或小写字母( abcdefghijklmnopqrstuvwxyz )。

在异于 "C" 的本地环境中,字母字符是 isupper()islower() 对其返回非零值的字符,或任何其他被本地环境认为是字母的字符。任何情况下, iscntrl()isdigit()ispunct()isspace() 将对此字符返回零。

若 ch 的值不能表示为 unsigned char 且不等于 EOF ,则行为未定义。

Parameters

c

  • Character to be checked, casted to an int, or EOF.
  • c - 要分类的字符

Return Value

  • A value different from zero (i.e., true) if indeed c is an alphabetic letter. Zero (i.e., false) otherwise.
  • 若字符为字母字符则为非零值,否则为零。

Example

//
// Created by zhangrongxiang on 2018/2/1 14:54
// File isalpha
//

#include <ctype.h>
#include <stdio.h>
#include <locale.h>

int main(void) {
    unsigned char c = '\xdf'; // ISO-8859-1 的德文字母 ß
    printf("isalpha('\\xdf') in default C locale returned %d\n", !!isalpha(c));  //0
    setlocale(LC_CTYPE, "de_DE.iso88591");
    printf("isalpha('\\xdf') in ISO-8859-1 locale returned %d\n", !!isalpha(c));//0

    int i = 0;
    char str[] = "I Love My Country!!";
    while (str[i]) {
        if (isalpha(str[i])) printf("character %c is alphabetic\n", str[i]);
        else printf("character %c is not alphabetic\n", str[i]);
        i++;
    }
    return 0;
}

文章参考

转载于:https://www.cnblogs.com/zhangrxiang/p/8399149.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值