大文字・小文字の変換
明解C言語 入門編 > 9. 文字列の基本 >
大文字・小文字の変換
C
#include <stdio.h>
#include <ctype.h>void str_toupper(char st[])
{
unsigned i = 0;
while (st[i])
{
st[i] = toupper(st[i]);
i++;
}
}void str_tolower(char st[])
{
unsigned i = 0;
while (st[i])
{
st[i] = tolower(st[i]);
i++;
}
}int main(int argc, char* argv[])
{
char str[100] = "BohYoh";str_toupper(str);
printf("大文字:%s\n", str);str_tolower(str);
printf("小文字:%s\n", str);return 0;
}
実行結果
R:\>lesson076\Project1.exe
大文字:BOHYOH
小文字:bohyoh