tolower()函数在ctype.h头文件中定义。如果传递的字符是大写字母,则tolower()函数会将大写字母转换为小写字母。
用法:
int tolower(int ch);
参数:此方法采用强制参数ch,该参数是要转换为小写字母的字符。
返回值:此函数返回对应于ch的小写字符。
以下示例程序旨在说明C语言中的tolower()函数:
示例1:
// C program to demonstrate
// example of tolower() function.
#include
#include
int main()
{
// Character to be converted to lowercase
char ch = 'G';
// convert ch to lowercase using toLower()
printf("%c in lowercase is represented as = %c", ch, tolower(ch));
return 0;
}
输出:
G in lowercase is represented as = g
示例2:
// C program to demonstrate
// example of tolower() function.
#include
#include
int main()
{
int j = 0;
char str[] = "GEEKSFORGEEKS\n";
// Character to be converted to lowercase
char ch = 'G';
// convert ch to lowercase using toLower()
char ch;
while (str[j]) {
ch = str[j];
// convert ch to lowercase using toLower()
putchar(tolower(ch));
j++;
}
return 0;
}
输出:
geeksforgeeks