C语言tolower()函数:将字符转换成小写
tolower()函数
头文件和函数原型
#include <ctype.h>
int tolower(int c);
描述
tolower()
是C语言标准库中的一个函数,用于将一个字符转换成对应的小写形式;
返回值
如果传入的字符参数是一个大写字母,tolower()
函数会返回其对应的小写字母;如果参数不是大写字母,则原封不动的返回;
示例代码
这个示例用于将字符串转换成小写形式;
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void str_tolower(char* str, signed length) {
for (int i = 0; i < length; i++) {
str[i] = tolower(str[i]);
}
}
int main() {
char str[] = "HELLO WORLD! 123";
printf("%s\n", str);
str_tolower(str, strlen(str));
printf("%s\n", str);
}
程序运行结果
HELLO WORLD! 123 hello world! 123