C语言判断英文字符大小写的方法

来源:爱站网时间:2021-01-15编辑:网友分享
在C语言开发中,编写程序要实现判断英文字符的大小写,并且需要菜单提示功能的完成,今天爱站技术小编就来告诉大家C语言判断英文字符的大小写吧!

在C语言开发中,编写程序要实现判断英文字符的大小写,并且需要菜单提示功能的完成,今天爱站技术小编就来告诉大家C语言判断英文字符的大小写吧!

C语言isupper()函数:判断字符是否为大写英文字母
头文件:

 #include 

定义函数:

int isupper(int c);

函数说明:检查参数c是否为大写英文字母。

返回值:若参数c 为大写英文字母,则返回非 0,否则返回 0。

附加说明:此为宏定义,非真正函数。

范例:找出字符串str 中为大写英文字母的字符。

#include 
main(){
  char str[] = "123c@#FDsP[e?";
  int i;
  for(i = 0; str[i] != 0; i++)
    if(isupper(str[i]))
      printf("%c is an uppercase character\n", str[i]);
}

执行结果:

F is an uppercase character
D is an uppercase character
P is an uppercase character

C语言islower()函数:判断字符是否为小写字母
头文件:

#include 

islower() 用来判断一个字符是否是小写字母,其原型为:

  int islower(int c);

【参数】c 为需要检测的字符。

【返回值】若参数c 为小写英文字母,则返回非 0 值,否则返回 0。

注意,此为宏定义,非真正函数。

【实例】判断str 字符串中哪些为小写字母。

#include 
main(){
  char str[] = "123@#FDsP[e?";
  int i;
  for(i = 0; str[i] != 0; i++)
    if(islower(str[i]))
      printf("%c is a lower-case character\n", str[i]);
}

输出结果:

c is a lower-case character
s is a lower-case character
e is a lower-case character

 

看了爱站技术频道介绍的C语言判断英文字符大小写的方法,希望以上内容会给大家开发有所帮助,如果有什么不懂的问题,也可以详细的咨询js.aizhan.com。

上一篇:C语言开发中二叉树的数据结构

下一篇:C语言开发中求解最小生成树的简便方法

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载