加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C语言isalpha()函数:判断一个字符是否是字母

发布时间:2020-12-15 17:30:22 所属栏目:百科 来源:网络整理
导读:C语言 isalpha() 函数用来检测一个字符是否是字母,包括大写字母和小写字母。 头文件:ctype.h 语法/原型: int isalpha(int c); 参数 c 表示要检测字符或者 ASCII 码。 返回值:返回非 0(真)表示 c 是字母,返回 0(假)表示 c 不是字母。 【实例】C语言 i
C语言 isalpha() 函数用来检测一个字符是否是字母,包括大写字母和小写字母。

头文件:ctype.h

语法/原型:

int isalpha(int c);

参数 c 表示要检测字符或者 ASCII 码。

返回值:返回非 0(真)表示 c 是字母,返回 0(假)表示 c 不是字母。

【实例】C语言 isalpha() 函数判断一个字符串中的字符是否是字母。
#include <stdio.h>
#include <ctype.h>
int main()
{
    int i = 0;
    char str[] = "C++ Java C#";
    while (str[i])
    {
        if (isalpha(str[i])) {
            printf("%c is alphabeticn",str[i]);
        }
        else {
            printf("%c is not alphabeticn",str[i]);
        }
        i++;
    }

    return 0;
}
运行结果:
C is alphabetic
+ is not alphabetic
+ is not alphabetic
? is not alphabetic
J is alphabetic
a is alphabetic
v is alphabetic
a is alphabetic
? is not alphabetic
C is alphabetic
# is not alphabetic

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读