Quote:
> Assuming that you're not dealing with UNICODE value.
Or any of a large number of other legal encodings.
Quote:
> Method 2:
> Check the decimal value of the characters. If it's between 97 and 122,
> substract 32:
> for( i = 0; str[i] != '\0'; i++ )
> {
> if( 122 >= str[i] >= 96 )
> str[i] -= 32;
> }
if (122 >= str[1] >= 96)
is legal, but will not do what you want. The check you want is
if (122 >= str[1] && str[1] >= 97) /* not 96 */
You may think that this is equivalent to
if ('z' >= str[i] && str[i] >='a')
but it is not. On an EBCDIC implementation, it is the same as
if (':' >= str[1] && str[1] >='/')
and
str[1] -= 32;
which is str[1] -= ' '; in ASCII, is just wrong on an EBCDIC machine,
where 'a' == 129 and 'A' == 193, so 'a' - 'A' == -64. Not only the value, but
the sign is wrong (note that ' '==64 in EBCDIC, so
abs('a'-'A') == ' ' in both).
Further, 'a' (129) through 'z' (169), includes "~{}\\" as well as 10 other codes
which you will not want to map.
Quote:
> Hope this will help.
I doubt it. Incorrect information is never a help unless clearly marked as
"Don't do this wrong thing." Your implementation does not define the world.
--