[C language] to create a function, use this function to convert a string of lowercase to uppercase

principle:

Such main subject by ASCII (American Standard Code for Information Exchange) codes achieve a difference, A decimal numbers corresponding to ASCII code 65, a decimal number corresponding to the ASCII code is 97, i.e., the case the difference between the ASCII code for the letters 32, like to uppercase letters to lowercase letters can be the character ASCII code value +32, empathy lowercase letters to uppercase characters only the ASCII value of -32

#include<stdio.h>
#include<assert.h>

char * my_strlwr ( char * STR)    // define a function my_strlwr 
{
    Assert (STR);          // STR of Nonemptiness 
    char * ret = STR;        // define a stored original ret STR 
    the while (STR * =! ' \ 0 ' )       // determines whether the end of the string 
    {  
         IF ((* STR> = ' a ' ) && (* STR <= ' Z ' )) // determines whether the current character lowercase 
        {
             * STR STR * = - 32 ;      // converted to uppercase 
            STR ++ ;
        }
        presence 
            size ++ ;
    }
    return RET;        // return the first address of the array of string 
}
 int main ()
{
    char str1[666];
    printf ( " Please enter a letter: \ the n- " );
Scanf ( " % S " , & str1); // input string of letters 

    the printf ( " % S \ n- " , my_strlwr (str1));   // call the function, and the new string

    return 0;
} 

 

Guess you like

Origin www.cnblogs.com/HGNET/p/11955521.html