私が気にする100の事象

気にしなければ始まらない。

islower関数

概要

C言語で文字が小文字が判定する関数です。 小文字なら真(0以外)、それ以外なら偽(0)を返します。 <ctype.h>#includeすることによって使うことができます。

定義

定義は次の通りになります。

int islower (int c);
機能 内容
第1引数 int 検査対象の文字
返り値 int 小文字なら真(0以外)、
それ以外なら偽(0)

仕様

ISO/IEC 9899:1999 における仕様を示します。

7.4.1.7 The islower function
Synopsis
1 #include <ctype.h>
int islower(int c);
Description
2 The islower function tests for any character that is a lowercase letter or is one of a locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or isspace is true. In the "C" locale, islower returns true only for the lowercase letters (as defined in 5.2.1).

また、JIS X 3010:2003 における仕様を示します。

7.4.1.7 islower 関数
形式 #include <ctype.h>
int islower(int c);
機能 islower関数は,小文字,又は iscntrl,isdigit,ispunct 若しくは isspace のいずれも真とならない文化圏固有の文字集合の中の文字かどうかを判定する。"C"ロケールでは,islowerは,小文字(5.2.1で定義)に対してだけ真を返す。

使用例

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

int main() {
    char c;
    system("cls");
    printf("  0123456789ABCDEF");
    for(c = 0x00; c < 0x7F; c++) {
        if (c % 16 == 0) printf("\n%x ", c / 16);
        printf("%s", isspace(c) ? "\033[41m" : "\033[0m");
        printf("%c", isprint(c) ? c :'.');
        printf("\033[0m");
    }
    printf("\n");
    return 0;
}

結果は以下のようになります。

./islower.exe
  0123456789ABCDEF
0                 
1                 
2                 
3                 
4                 
5                 
6  abcdefghijklmno
7 pqrstuvwxyz    

真のときに文字が表示されているように見えますが、 実際には赤い背景色が文字を囲んでいます。

コンパイラEmbarcadero C++ 7.20です。

bcc32c --version
Embarcadero C++ 7.20 for Win32 Copyright (c) 2012-2016 Embarcadero Technologies, Inc.
Embarcadero Technologies Inc. bcc32c version 3.3.1 (35832.6139226.5cda94d) (based on LLVM 3.3.1)
Target: i686-pc-win32-omf
Thread model: posix

実装例

int islower (int c) {return 'a' <= c && c <= 'z';}
最悪計算時間 最良計算時間 平均計算時間 最悪空間計算量
 O(1)
 O(1)
 O(1)
 O(1)

最終更新日: 2018-05-21