tolower()函数在ctype.h头文件中定义。如果传递的字符是大写字母,则 tolower() 函数将大写字母转换为小写字母。
语法:
参数:该方法需要一个强制参数ch,它是要转换为小写的字符。
返回值:该函数返回ch对应的小写字符。
下面的程序说明了 C 中的 tolower() 函数:
示例 1:-
输出:
输出:
输出
int tolow(int ch);
// C program to demonstrate
// example of tolower() function.
#include <ctype.h>
#include <stdio.h>
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 <ctype.h>
#include <stdio.h>
int main()
{
int j = 0;
char str[] = "CXYDHn";
// Character to be converted to lowercase
char ch = 'C';
// 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;
}
cxydh笔记: 如果在 tolower() 中传递的字符是这三个中的任何一个 1.小写字符 2.特殊符号 3. 数字 tolower() 将按原样返回字符。 例子 :
// C program to demonstrate
// example of tolower() function.
#include <ctype.h>
#include <stdio.h>
int main()
{
int j = 0;
char str[] = "Cxydh@123n";
char ch;
while (str[j]) {
ch = str[j];
putchar(tolower(ch));
j++;
}
return 0;
}
cxydh@123