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

C語言isupper函數用於判斷字符是否爲大寫字母(A-Z)。

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

1、包含頭文件

#include <ctype.h>

2、函數聲明

int isupper(int c);

3、功能說明

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

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

4、示例

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

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

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

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

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

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

// 自定義的isupper函數。
int _isupper(int c)
{
  if (c>='A' && c<='Z') return 256;

  return 0;
}

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

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

6、版權聲明

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

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

作者:碼農有道

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

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