C tolower()

tolower() 函数在 ctype.h 头文件中定义。它有助于将给定的大写字符转换为小写字符。


int tolower(int argument); #where argument will be a character
 

tolower() 参数

tolower() 函数接受一个参数,其形式为整数。当传递字符时,它会转换为与其 ASCII 值对应的整数值。

参数 描述 必需/可选
参数 需要转换的字符 必需

tolower() 返回值

此函数将给定的大写字符转换为小写字符。该值以整数值形式返回,可以隐式转换为 char。如果传递的参数不是大写字母,它将返回相同的传递字符。

输入 返回值
大写字符 对应的小写字符
小写字符或非字母字符 字符本身

tolower() 示例

示例 1:C 语言中 tolower() 函数的工作方式


#include <stdio.h>
#include <ctype.h>
int main()
{
    char ch, output;

    ch = 'A';
    output = tolower(ch);
    printf("tolower(%c) = %c\n", ch, output);

    ch = 'a';
    output = tolower(ch);
    printf("tolower(%c) = %c\n", ch, output);

    ch = '+';
    output = tolower(ch);
    printf("tolower(%c) = %c\n", ch, output);

    return 0;
}

输出


tolower(A) = a
tolower(a) = a
tolower(+) = +

示例 2:C 语言中 tolower() 函数的工作原理?


#include <stdio.h>
#include <ctype.h>
int main () {
   int k = 0;
   char ch;
   char st[] = "PROGRAMMING";
 
   while( st[k] ) {
      putchar(tolower(st[k]));
      k++;
   }
   
   return(0);
}

输出


programming