C 语言大写转小写

17 Mar 2025 | 5 分钟阅读

本节将讨论在 C 编程语言中将大写字母(字符或字符串)转换为小写的不同程序。大写字母是字母表中的大写字母。例如,大写字母是 A、B、C、D、...、X、Y、Z。类似地,小写字母由字母表中的小写字母表示。例如,小写字母是 a、b、c、d、e...、w、x、y、z。

当我们使用 ASCII 码将大写字母或字符串转换为小写时,此过程会将 C 编程中的大写字母转换为小写字母。大写字母 (A - Z) 的 ASCII 值范围是 65 到 90,小写字母 (a - z) 的 ASCII 值范围是 97 到 122。

例如,我们有一个大写字母“A”,并想将其转换为小写字母“a”,我们需要将 32 添加到 A 的 ASCII 值 (65),这将返回字符“a”,其 ASCII 值为 97 (65 + 32)。类似地,我们可以将大写字符串“HELLO”转换为小写字符串“hello”。

Convert Uppercase to Lowercase in C

将大写字符转换为小写的程序

让我们编写一个程序,在 C 编程语言中将大写字符转换为小写字符。

Program1.c

输出

Enter the Upper Case Character: A
 A character in Lower case is: a
 Enter the Lower Case Character: z
 z character in the Upper case is: Z

使用 for 循环将大写字符串转换为小写的程序

让我们编写一个简单的程序,在 C 编程中使用 for 循环将大写字符串转换为小写。

Program2.c

输出

Enter the string: WELCOME

 Upper Case to Lower case string is: welcome

使用 while 循环将大写字符串转换为小写的程序

让我们考虑一个示例,在 C 编程中使用 while 循环从大写字符串打印小写字符串。

Program3.c

输出

Enter an upper case string: CPROGRAMMING

 The lowercase string is: cprogramming

使用 strlwr() 函数将大写字符串转换为小写的程序

Strlwr() 函数:strlwr() 函数是字符串库的预定义函数,用于通过将给定字符串作为参数传递来将其转换为小写字符串,以返回小写字符串。

语法

strlwr() 函数有一个 upr 参数,表示大写字符串,strlwr() 函数接受 upr 参数以返回一个小写字符串。

让我们创建一个程序,在 C 编程中使用内置的 strlwr() 函数将大写字符串转换为小写。

Program4.c

输出

Enter the upper case string: GOOD BYE

 The lowercase string is: good bye

使用用户定义函数将大写字符串转换为小写的程序

让我们考虑一个示例,在 C 编程中使用用户定义函数将大写字符串转换为小写。

Program5.c

输出

Enter the upper case string: JAVATPOINT

 The lowercase string is: javatpoint

使用递归函数将大写字符串转换为小写的程序

让我们考虑一个示例,在 C 编程中使用递归函数从大写字符串打印小写字符串。

Program6.c

输出

Enter the upper case string: C PROGRAMMING LANGUAGE

The lowercase string is: c programming language