case convertion from lower ro upper and vice versa

+1 ragmar thomas · July 19, 2014
how to convert a random string from the user to upper or lower case just like a dictionary application whether the user typed it in upper case or lower case it search if possible with out any header files.

Post a Reply


- page 1
Oldest  Newest  Rating
+2 Brandon Elliott · August 1, 2014
Some people really like to argue :silly:
+1 Dima Sama · August 1, 2014
You have a point and i support you for that. But let me just clarify things.

You're right; He probably isn't getting paid for this program... Not for this program, no.

This is one of the programs that helps him get his diploma.

THEN he'll get paid... but when he can't find an example of what he wants to do at work, he'll think back to those days when people did work for him here, and he'll ask around here.

You just assume he is a college student. I'm not saying he is not, but its best not to assume things. He didn't even mention what he is. Anyway, i doubt he never tried to think on his own. So let's not assume. He'll think back to those days and ask around here? Really? You'd think someone will dare answer him if he ever ask how to make a database on a certain company? I don't think so.

isupper/lower/etc and toupper/lower/etc are documented to take an int argument, which is then treated as though it's an unsigned char value. Giving them negative char values is undefined behaviour, and actually causes assertion errors for some implementations, eg.

If someone tried to explain like that i don't think he really understood c++ that well. It's no different from reading a book. Try answering like that and you would be bombarded with another questions no different from the initial one. For god's sake if my tutor put a site like that he failed miserably.

In addition, it's best not to encourage or rely upon ASCII tricks (such as adding or subtracting 32) because they're not future-proof (or even past-proof). Neither C nor C++ require that ASCII be used as the character set; EBCDIC is equally valid. Though rare as it is in this day and age, your advice will presumably be there forever; You wouldn't want to be seen giving invalid advice some day, would you?

There's a reason i explained ascii tricks on the bottom right? I never mention he/she should use that. I'm just merely giving him/her some options. I also include it so that he/she can understand the logic behind that conversion.

I don't care what others see or think of me. I'm not asking for fame or money. I'm just helping. You can ignore my advice if it was deem useless or invalid but it doesn't change the fact that i'm just helping right?

The best thing to "explain to him" is that which he has yet to understand, and you can't do that without first determining what he has tried.

In this case, he posted no code. Ask him to post code! Ask him what he's tried! Ask him what he didn't understand! If you don't do these things, if you just spoonfeed him... You're failing him.

Yes i agree to you with this one. But if you really read his question you will know what he didn't understand. And if you really reading this thread you should have known my first response to this thread and our initial conversation.
0 ragmar thomas · August 2, 2014
for the record this was an assignment nearly a month a go and trust me it was the best when i presented it because it wasn't copied and pasted after what i have earned what i deserve i wasn't satisfied with what i have accomplished i want it to be better so i need to find someone better particularly here and not yet i ain't even planning to be payed at most nearly (and back to the problem do you guy know any ways to work with strings and fstream , thanks in advance and i hate copy and paste trust me 'm old enough to hate it and i don't what to do my work for me just little help tips that's it)
0 ragmar thomas · August 2, 2014
lol you have all lost me i have already a diploma or what ever you call it of course in other filed and lately 'm kind interested in the tech world not for the sake of carrier but for passion(and hopefully one day it will be my carrier) it's been about 10 month since i enrolled to my new course and its my first programming language to start again to my topic it gives unexpected results while using char and string with cotes when comparing them with each other.

And btw there were offensive comments am old enough not to feel about the BS if i were a teenage or my first college tour it would have been a disaster and please don't bash smash someone work just like that(this no different than bullying) who ever you are probably you were the worst or had been through try to be positive there might be kids out here or there please am begging you not for me off course.peace   
0 ragmar thomas · August 2, 2014
waow you have issues, dude trust me i have already A+ in my previous course i just posted this for my own sake i want to be a kick-ass for real in this language and please enough with the BS thing if you know how to help me do it then other wise go some where else and play candy crash kid.
0 ragmar thomas · July 30, 2014
the code below try to resemble for a dictionary that helps the user to enter new words but it wont over write i used string data type but it want overwrite new words there is a way to solve this with fstream but it impossible for me to make it work and i have a feeling the data type must be char to work with fstreams and i have limitation using char very hard to deal with 

#include <iostream>
using namespace std;
int main(){
   string meaning, index, enter, add, newWord;
cout << "Dictionary" << endl;
cout << "Search word" << endl;
cout << "Enter word" << endl;
cout << "To quit dictionary press q" << endl;
cin >> index;
if(index == "car")
    cout << " manned vehicle " << endl;
        cout << " a machine use for calculating bulky numbers accurately and faster" << endl;
        cout << " just having supper nice whatever stuffs" << endl;
        if(index==add){goto x;
        cout << meaning;}
    cout << "word not found!" << endl;
    cout << "you want to add word to dictionary (y/n): ";
    cin >> enter;
        cout << "please enter your new word: " << endl;
    getline(cin, add);
    cout << "please enter your new word's meaning: " << endl;
    getline(cin, meaning);
    cout << "your new word's meaning: " << endl;x:
    cout << meaning << endl;
    cout << "enter any word to search for: ";
goto there;}

0 ragmar thomas · July 21, 2014
thanks in advance, just want to change the hole word to be changed in either way just like a dictionary application i have just made one but it its to embarrassing to post it here i just want just when ever the user typed a word whether lower or upper case the program retrieves the meaning of the word if it is saved before <simply just a way of changing the case of the words i have seen one but i can remember where is it now in the internet i think it is like + 32 or -32>
0 Dima Sama · July 21, 2014
Well i don't know how you want to use it but if you want to convert a small letter to capital and vice versa there are two ways. I can give you an example plus an idea.

The first way is to use cctype library

#include <iostream>
#include <cctype>

int main()

        cout << endl << endl;
        cout << "Welcome to the Letter Changing.\n\n"
             << "Enter a sentence and end it with @:\n";

        char letterInput;

        while (cin.get(letterInput) && letterInput != '@') // Loop that will end if either the input is incorrect or with @ sign
            if (isalpha(letterInput)) // If the input is alphabetic execute the statement below, else print the original letter
                cout << char(isupper(letterInput) ? tolower(letterInput) : toupper(letterInput)); // if input is upper change to lower, else change it to upper.
                cout << letterInput;

        return 0;


First you need to do a number reading loops like this code:

while (cin.get(letterInput) && letterInput != '@') 

This code means that as long as the input did not fail the loop will continue. The condition which is cin.get(letterInput) is another way to prompt the user to input. It does the same as an ordinary cin >> letterInput. After the user entered an input cin.get() buffered the next input in line.

            if (isalpha(letterInput)) // If the input is alphabetic execute the statement below, else print the original letter
                cout << char(isupper(letterInput) ? tolower(letterInput) : toupper(letterInput)); // if input is upper change to lower, else change it to upper.
                cout << letterInput;

This code here do all the  convertion. You need cctype library to use the isalpha(), isupper(), tolower() and toupper(). isalpha() checks whether the user enter an alphabet. If the user entered space, number, punctuation or newline the program will just output it.

If the user entered an alphabet that's where the conversion starts. This statement here is like an if else statement:

 char(isupper(letterInput) ? tolower(letterInput) : toupper(letterInput));

isupper(letterInput) checks if the user entered a Capital letter. If the user entered a capital letter isupper() will be true and then tolower() will convert it to lower letter and if the user did not entered capital letter toupper() will convert it to capital letter. The char in the first statement encapsulate them all because after the evaluation they will changed to int type so we need to typecast it to char type and send it to cout to print.

The other way is using the ascii number of the letter. It is as the same with the previous example you just need to change the contents of if else statement.
It's like this

if(letterInput >= 'A' && letterInput <= 'z')
      cout << char((letterInput >= 'A' && letterInput <= 'Z') ? letterInput + 32 : letterInput - 32)

The reason for using +32 and -32 because the distance between capital "A" to lower capital "a"  is 32.

You can also use nested if else but it will be too long.

I hoped i helped. :)

Tell me if there's something you didn't understand.
0 Brandon Elliott · July 21, 2014
hmm... all this for a task so simple in Java.

String.toLowerCase() or String.toUpperCase()

0 Dima Sama · July 21, 2014
I don't know how to use java but i searched about the string.tolower, it says that it convert all string to lower, right? well that's convenient. :)

Maybe ill need to learn some java. It seems really popular.
  • 1
  • 2



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator