----- Original Message -----
From: "vinayak bhat" <vinubhagwat@yahoo.co.in>
To: <UTTARA@yahoogroups.com>
Sent: Wednesday, December 24, 2003 8:40 PM
Subject: [UTTARA] query
> frndz
> i have a question,
>
> write a C pgm to convert lower case to upper case and upper case
> to lower case without using arithmetic operators and library functions
>
#include <stdio.h>
#include <stdlib.h>
/*
* Notice that
*/
int
_tolower ( int ch )
{
unsigned char _ch = (unsigned char)ch >> 4;
/* If CH is already in lower case, return it */
if ( _ch == 0x6 || _ch == 0x7 )
return ch;
/* convert it to lower case */
if ( _ch == 0x4 )
return (int)( ( (unsigned char)ch & 0x0f ) | 0x60 );
else
if ( _ch == 0x5 )
return (int)( ( (unsigned char)ch & 0x0f ) | 0x70 );
else
return ch;
}
int
_toupper ( int ch )
{
unsigned char _ch = (unsigned char)ch >> 4;
/* If CH is already in upper case, return it */
if ( _ch == 0x4 || _ch == 0x5 )
return ch;
/* convert it to upper case */
if ( _ch == 0x6 )
return (int)( ( (unsigned char)ch & 0x0f ) | 0x40 );
else
if ( _ch == 0x7 )
return (int)( ( (unsigned char)ch & 0x0f ) | 0x50 );
else
return ch;
}
int
main ( void )
{
printf ( "%c\n", _toupper ( '+' ) );
printf ( "%c\n", _toupper ( 'r' ) );
printf ( "%c\n", _toupper ( 'l' ) );
printf ( "%c\n", _toupper ( 'P' ) );
printf ( "%c\n", _tolower ( '$' ) );
printf ( "%c\n", _tolower ( 'R' ) );
printf ( "%c\n", _tolower ( 'O' ) );
printf ( "%c\n", _tolower ( '9' ) );
return 0;
}