Tom Knowlton
asked on
tolower done manually
I know that ctype.h has a tolower function.
If I wanted to write one manually...how is it done?
Thanks!
If I wanted to write one manually...how is it done?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
same thing :))
ch + 32 is gonna be executed faster than ch + 'a' - 'A' :))
ch + 32 is gonna be executed faster than ch + 'a' - 'A' :))
Personally, I have no faith in optimizers, but even the worst optimizer had better catch that.
with today's pentium II, there will not be much difference between the two..
both make an assumption about your locale
'A' is more obvious than 65 (and makes fewer assumtions about your character set)
'A' is more obvious than 65 (and makes fewer assumtions about your character set)
ASKER
Viktornet:
Your answer sounded good to me. Haven't actually tried it yet, but I'm sure it works.
Thanks,
Tom
Your answer sounded good to me. Haven't actually tried it yet, but I'm sure it works.
Thanks,
Tom
This reminds me of the assembly days, when I used a bit operation to convert to lower or upper case.
These macro should do the work
#define ToUpper(ch) (((ch) >= 'a' && (ch) <= 'z') ? ((ch) & ~0x20) : (ch))
#define ToLower(ch) (((ch) >= 'A' && (ch) <= 'Z') ? ((ch) | 0x20) : (ch))
Regards,
Wenderson
These macro should do the work
#define ToUpper(ch) (((ch) >= 'a' && (ch) <= 'z') ? ((ch) & ~0x20) : (ch))
#define ToLower(ch) (((ch) >= 'A' && (ch) <= 'Z') ? ((ch) | 0x20) : (ch))
Regards,
Wenderson
char ToLower(char ch)
{
if (ch >= 'A' && ch <= 'Z')
return (ch+'a'-'A');
}