qc.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
CASE.C
                                             Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
/* CASE.C illustrates case conversion and other conversions.
 * Functions illustrated include:
 *      strupr          toupper         _toupper
 *      strlwr          tolower         _tolower
 *      strrev          toascii
 */
 
#include <string.h>
#include <stdio.h>
#include <ctype.h>
 
char mstring[] = "Dog Saw Dad Live On";
char *ustring, *tstring, *estring;
char *p;
 
void main()
{
    printf( "Original:\t%s\n", mstring );
 
    /* Upper and lower case */
    ustring = strupr( strdup( mstring ) );
    printf( "Upper case:\t%s\n", ustring );
 
    printf( "Lower case:\t%s\n", strlwr( ustring ) );
 
    /* Reverse case of each character. */
    tstring = strdup( mstring );
    for( p = tstring; *p; p++ )
    {
        if( isupper( *p ) )
            *p = tolower( *p );
        else
            *p = toupper( *p );
 
        /* This alternate code (commented out) shows how to use _tolower
         * and _toupper for the same purpose.
        if( isupper( *p ) )
            *p = _tolower( *p );
        else if( islower( *p ) )
            *p = _toupper( *p );
         */
    }
    printf( "Toggle case:\t%s\n", tstring );
 
    /* Encode and decode string. The decoding technique will convert
     * strings with some high bits set (produced by some word processors).
     */
    estring = strdup( mstring );
    for( p = estring; *p; p++ )
        *p = *p | 0x80;
    printf( "Encoded:\t%s\n", estring );
 
    for( p = estring; *p; p++ )
        *p = toascii( *p );
    printf( "Decoded:\t%s\n", estring );
 
    printf( "Reversed:\t%s\n", strrev( ustring ) );
}