Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert uppercase letters to lowercase in C language

Shulou Source: shulou.com Published: 2022-06-01 01:38:44 10月03日 Update

The editor of this article introduces in detail "how to convert uppercase letters to lowercase in c language". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to convert uppercase letters into lowercase in c language" can help you solve your doubts. Let's follow the editor's train of thought to learn new knowledge.

#! / bin/bash

# name: upper_to_lower.sh

# the function is trun uper to lower

# like ABCd to abcd

Haveuppernumber ()

{

# test if the string have upper number

Str= "$(echo $1 | tr'[: upper:]'[: lower:]')"

If ["$str"! = $1]; then # get some problem

Echo "[# have upper number,and i well trun them to lower:#]"

Return 1 # have upper number

Else

Return 0 # no upper number

Fi

}

If [$#-ne 1]; then

Echo "Usage: $0" > & 2

Exit 1

Fi

If! Haveuppernumber $1; then # when if is 0 it run?

# if [0]; then # in shell true return 0, false return 1

Echo $1 | tr'[: upper:]'[: lower:]'# it can turn the UPPER number to lower

# echo $1 | tr'[: lower:]'[: upper:]'# it can turn the lower number to UPPER

Else

Echo "[# no upper number:#]"

Echo $1

Fi

Exit 0

Function description: when entering ". / upper_to_lower.sh AaBbCcdd" will first determine whether the input format is correct, and then determine whether there are uppercase letters in the string if there is a display of "[# have upper number,and i well trun them to lower:#]" and the string converted to lowercase letters; if there are no uppercase letters display "[# no upper number:#]" and lowercase string.

Then try to achieve the same function in C language, as follows:

The code is as follows:

# include

# include

Int haveuppernumber (char * p)

{

Char*q=p

For (; * QQ stories'\ 0percent investors +)

{

If (* Q > = 'Asians, girls, boys, girls, boys, girls, girls, boys, girls,

Tags: Letters uppercase uppercase lowercase language characters strings articles content functions input proper same code ideas new knowledge more formats steps knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Microsoft Redmi Shulou Technology