Trying to convert uppercase char to lowercase in C without using a function

后端 未结 4 696
耶瑟儿~
耶瑟儿~ 2021-01-27 02:58

I am trying to convert a char element from an char *argv[] array to lowercase from uppercase without using a function. I want to add 32 to the ascii integer.

When I try

4条回答
  •  青春惊慌失措
    2021-01-27 03:24

    First, don't assume you are using an ascii character set (ie, 32 is the wrong additive value in some character sets). The problem you are having is that 'h' + 32 is not a lower case "h". 'h' is already lowercase, so you want to be adding 0. Check it; something like:

    if( tolower >= 'A' && tolower <= 'Z' )
      tolower += 'a' - 'A';
    

提交回复
热议问题