当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


C语言 isalpha()用法及代码示例

该函数用于检查字符是否为字母。如果字符是字母,则函数返回零,如果不是,则函数返回零。

此函数相当简单,不提供有关小写字母或大写字母的信息。对于这些情况,您必须使用不同的函数。

该函数可以通过检查字符的 ascii 值轻松实现,然后它会相同但结果准确。

该函数占用一个字符并返回一个整数。

例:

    Input character is:‘a’
    Function will return 1


    Input character is:‘@’
    Function will return 0

ctype.h - C 中的 isalpha() 函数示例


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

int main()
{
    // defining the type of variable
    char a,b;

    // assigning the value of variable
    a = 'A';
    b = '1';

    // condition to check the character
    if (isalpha(a) != 0)
    {
        printf("%c is an alphabet\n", a);
    }
    else
    {
        printf("%c is not an alphabet\n", a);
    }

    // condition to check the character
    if (isalpha(b) != 0)
    {
        printf("%c is a the alphabet\n", b);
    }
    else
    {
        printf("%c is not a the alphabet\n", b);
    }

    return 0;
}

输出

ctype.h - isalpha()  in c language



相关用法


注:本文由纯净天空筛选整理自Abhishek Sharma大神的英文原创作品 isalpha() function of ctype.h in C。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。