このエントリーをはてなブックマークに追加


大文字を小文字に変換する・tolower

C言語で英字の大文字を小文字に変換するにはtolower関数を使用します。
以下にサンプルコードと実行例を記します。


スポンサーリンク

関連記事

tolower関数の書式等

以下にtolower関数の書式等を記します。

  • 必要なインクルードファイル
    #include <ctype.h>
  • 書式
    int tolower(int c);
  • 戻り値
    英字小文字に変換したコード値が返却されます。
  • 引数
    小文字に変換する文字

tolower関数のサンプルコード

以下にtolower関数を使用したC言語サンプルコードを記します。
filetolower.c (改行コードLF)

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

int main(void)
{
    char *ascii = "01abCD$?";
    char buf[100];
    int i;

    memset(buf, '\0', sizeof(buf));

    for (i=0; i<strlen(ascii); i++) {
        buf[i] = (char)tolower(ascii[i]);
    }

    printf("before: %s\n", ascii);
    printf("after : %s\n", buf);

    return 0;
}

上記のサンプルコードをコンパイルし実行した結果を以下に記します。

$ gcc tolower.c -o tolower
$ ./tolower 
before: 01abCD$?
after : 01abcd$?

以上、tolower関数のサンプルコードでした。


スポンサーリンク

添付ファイル: filetolower.c 404件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-03-20 (金) 21:01:00