Hi..

I want to write a C++ program which reads a text from the user
and change any uppercase letter to an lowercase letter and assign them to an stack??

please help..

Recommended Answers

All 5 Replies

Well, you can try this:

1) Check if it is an Uppercase letter.(Using the ASCII value)

2) If it is, add 32 to it.(convert it to lower case)

Ascii Table

Is there a toUpper or toLower in C/++ ?

Is there a toUpper or toLower in C/++ ?

The ctype.h library has functions

int toupper(int c);
int tolower(int c);

Hi..

look at this code:

if( char >= 65 || char <= 90 )
   char = static_cast< char >( char + 32 );
cout<<char;

after reading the char if its uppercase add to it 32 and then assign it to char.

char is a keyword, you can't use it for a variable name. And don't use magic numbers. If you must rely on ASCII (std::tolower exists for a reason), at least use character literals:

if (c >= 'A' && c <= 'Z')
    c += 'a' - 'A';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.