怎么用C语言里函数转换大小写?

如题所述

用<ctype.h>中的函数tolower和toupper。前者以大写的字符作为参数,返回相应的小写字符;后者以小写的字符作为参数,返回相应的大写字符。
#include <ctype.h>
#include <stdio.h>
int main()
{
char c = 'A';
printf("%c", tolower(c)); //a
c = 'b';
printf("%c", toupper(c)); //B
return 0;
}
如果没有相应的大小写,函数会返回字符本身。
#include <ctype.h>
#include <stdio.h>
int main()
{
char c = '0';
printf("%c", tolower(c)); //0
printf("%c", toupper(c)); //0
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2019-08-01
函数名: tolower
功 能: 把字符转换成小写字母
用 法: int tolower(int c);
程序例:

#include
#include
#include

int main(void)
{
int length, i;
char *string = "THIS IS A STRING";

length = strlen(string);
for (i=0; i {
string[i] = tolower(string[i]);
}
printf("%s\n",string);

return 0;
}

函数名: toupper
功 能: 把字符转换成大写字母
用 法: int toupper(int c);
程序例:

#include
#include
#include

int main(void)
{
int length, i;
char *string = "this is a string";

length = strlen(string);
for (i=0; i {
string[i] = toupper(string[i]);
}

printf("%s\n",string);

return 0;
}本回答被网友采纳
第2个回答  2019-07-16
函数名:
tolower

能:
把字符转换成小写字母

法:
int
tolower(int
c);
程序例:
#include
#include
#include
int
main(void)
{
int
length,
i;
char
*string
=
"THIS
IS
A
STRING";
length
=
strlen(string);
for
(i=0;
i
{
string[i]
=
tolower(string[i]);
}
printf("%s\n",string);
return
0;
}
函数名:
toupper

能:
把字符转换成大写字母

法:
int
toupper(int
c);
程序例:
#include
#include
#include
int
main(void)
{
int
length,
i;
char
*string
=
"this
is
a
string";
length
=
strlen(string);
for
(i=0;
i
{
string[i]
=
toupper(string[i]);
}
printf("%s\n",string);
return
0;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网