This function converts a string to lowercase usering OR

char *ToLowerCase(char *text) {
	char *str = new char[strlen(text)];
	register int i;
	for (i=0;text[i];i++)
		str[i] = text[i] >= 'A' && text[i] <= 'Z' ?
		text[i] | 32 : text[i];
	str[i] = '\0';
	return str;
}

Well thats pretty easy.

Use the library

cctype

#include <cctype>

And then you can use the tolower command. It just is opposite of toupper.

char c;
cin>>c;
char d=tolower(c);
cout<<d;

Then that code takes in a character and converts into lowercase.

Comments
Excellent!!

It works because each character contains a value, for example:

'A' is equal 65 // 01100001

01000001 // 65
OR    00100000 // 32
     ----------
      01100001 // 97

97 = 'a'

> It works because each character contains a value
It works because you assume the the character set is contiguous, and is basically US-ASCII
Read about http://en.wikipedia.org/wiki/EBCDIC
Then read about locales.

Using toupper() etc will hide the locale and encoding details from you.


> char *str = new char[strlen(text)];
You also forgot to allocate space for the \0 at the end.

> It works because you assume the the character set is contiguous, and is basically US-ASCII
Or Unicode, and Unicode is the future of character sets. Edward definitely recommends toupper, but when was the last time you worked on an IBM mainframe? ;)

This question has already been answered. Start a new discussion instead.