#navi(contents-page-name): No such page: 文字列

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

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

c-top.html is not found or not readable.

関連記事

toupper関数の書式等

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

toupper関数のサンプルコード

以下にtoupper関数を使用したC言語サンプルコードを記します。

&ref(): File not found: "toupper.c" at page "文字列/小文字を大文字に変換する・toupper"; (改行コード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)toupper(ascii[i]);
    }

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

    return 0;
}

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

$ gcc toupper.c -o toupper
$ ./toupper 
before: 01abCD$?
after : 01ABCD$?

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

c-btm.html is not found or not readable.

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS