tolower 在 C 语言中的用法
tolower() 函数是 C 标准库中用于转换字符小写的函数。它接受一个 int 类型的 ASCII 码值作为参数,并返回该字符的小写版本。如果输入不是 ASCII 码值,则返回原值。
语法:
<code class="c">int tolower(int c);</code>
参数:
立即学习“C语言免费学习笔记(深入)”;
c:要转换的字符的 ASCII 码值。
返回值:
如果输入是 ASCII 码大写字母,则返回其小写版本。 如果输入是 ASCII 码小写字母或不是字母,则返回原值。用法:
tolower() 函数常用于将字符串转换为小写。下面是一个示例:
<code class="c">#include <stdio.h>
#include <string.h>
int main() {
char str[] = "THIS IS A STRING";
// 将字符串转换为小写
for (int i = 0; i < strlen(str); i++) {
str[i] = tolower(str[i]);
}
printf("小写字符串:%s\n", str);
return 0;
}</code>输出:
<code>小写字符串:this is a string</code>
