◄Up► ◄Contents► ◄Index► ◄Back► ─────Run-Time Library─────────────────────────────────────────────────────── /* 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 ); /* Uppercase and lowercase */ ustring = _strupr( _strdup( mstring ) ); printf( "Uppercase:\t%s\n", ustring ); printf( "Lowercase:\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 ) ); } -♦-