Home >Backend Development >C#.Net Tutorial >How to use tolower in c language

How to use tolower in c language

下次还敢
下次还敢Original
2024-05-02 18:33:32645browse

tolower() function converts characters to lowercase, accepts ASCII code values ​​and returns the corresponding lowercase version. This function is often used to convert a string to lowercase. The parameter is the ASCII code value of the string. If the input is an uppercase letter, lowercase is returned. If it is a lowercase letter or non-letter, the original value is returned.

How to use tolower in c language

Usage of tolower in C language

tolower() function is used to convert characters in the C standard library Lowercase functions. It accepts an ASCII value of type int as a parameter and returns the lowercase version of the character. If the input is not an ASCII value, the original value is returned.

Syntax:

<code class="c">int tolower(int c);</code>

Parameters:

  • c: The character to be converted ASCII code value.

Return value:

  • If the input is an ASCII uppercase letter, its lowercase version is returned.
  • If the input is ASCII lowercase letters or not letters, the original value will be returned.

Usage:

tolower() function is often used to convert strings to lowercase. Here is an example:

<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>

Output:

<code>小写字符串:this is a string</code>

The above is the detailed content of How to use tolower in c language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn