Use functions toupper() and tolower() to convert character case - C String

C examples for String:String Function

Description

Use functions toupper() and tolower() to convert character case

Demo Code

#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main( void )
{
    char buf[80];
    int  ctr;/*from   ww  w  .  j a  v a  2s  .  com*/

    while (1)
    {
        puts("Enter a line of text, a blank to exit.");
         gets_s(buf);

        if ( strlen(buf) == 0 )
            break;

        for ( ctr = 0; ctr< strlen(buf); ctr++)
        {
           printf("%c", tolower(buf[ctr]));
        }

        printf("\n");
        for ( ctr = 0; ctr< strlen(buf); ctr++)
        {
           printf("%c", toupper(buf[ctr]));
        }
        printf("\n");
    }
    return 0;
}

Result


Related Tutorials