C語言islower函數介紹、示例和實現

C語言islower函數用於判斷字符是否爲小寫字母(a-z)。

在本文中,我們先來介紹islower函數的使用方法,然後編寫一個自定義的_islower函數,實現與islower函數相同的功能。

1、包含頭文件

#include <ctype.h>

2、函數聲明

int islower(int c);

3、功能說明

判斷參數c是否爲小寫字母,您可能會問:islower函數的參數是int c,是整數,不是字符,在C語言中,字符就是整數,請補充學習一下基礎知識。

返回值:0-不是小寫字母,非0-是小寫字母。

4、示例

/*
 * 程序名:book.c,此程序演示C語言的islower函數。
 * 作者:C語言技術網(www.freecplus.net) 日期:20190525
*/
#include <stdio.h>

int main()
{
  printf("islower('-')=%d\n",islower('-'));
  printf("islower('0')=%d\n",islower('0'));
  printf("islower('a')=%d\n",islower('a'));
  printf("islower('A')=%d\n",islower('A'));
}

運行效果
在這裏插入圖片描述

5、自定義的islower函數的實現方法

在以下示例中,把自定義的islower函數命名爲_islower。

/*
 * 程序名:book.c,此程序演示C語言自定義的islower函數。
 * 作者:C語言技術網(www.freecplus.net) 日期:20190525
*/
#include <stdio.h>

// 自定義的islower函數。
int _islower(int c)
{
  if (c>='a' && c<='z') return 512;

  return 0;
}

int main()
{
  printf("_islower('-')=%d\n",_islower('-'));
  printf("_islower('0')=%d\n",_islower('0'));
  printf("_islower('a')=%d\n",_islower('a'));
  printf("_islower('A')=%d\n",_islower('A'));
}

運行效果
在這裏插入圖片描述

6、版權聲明

C語言技術網原創文章,轉載請說明文章的來源、作者和原文的鏈接。

來源:C語言技術網(www.freecplus.net

作者:碼農有道

如果這篇文章對您有幫助,請點贊支持,或在您的博客中轉發此文,讓更多的人可以看到它,謝謝!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章