# String arrays exercise

 Gent Ymeri · May 15, 2015 Hi!First of all I want to introduce myself.My name is Gent and I come from Europe.I am a first year student doing a B.Sc in BusinessInformatics (in U.S is knows as Information Systems/ Information Technology as I know)In this semester I have started to learn programming and I have a question which I can't solve without errors, if you guys can help me solve it, I would be thankful. The question is about String Arrays. Allow user to enter one text, then: a) Print the entered text in reverse order. and b) in the reverse text replace each lower case letter with upper case and vice versa. Thank you in advance!

## Replies

 Sengngy Kouch · May 20, 2015 Any time man! Gent Ymeri · May 20, 2015 Sengngy Kouch I see, that looks something similar to binary search.? Michael and Sengngy, thanks! Sengngy Kouch · May 19, 2015 @Michael : good advice Michael Bradford · May 19, 2015 Yeah just to reiterate since your learning what you have isn't really an array of strings so much as an array of char's. Strings are Chars (like 'M') strung together. Your professor called it a "string Array" which I find could be confusing to a new student.. It is an array of chars which is also known as a String. Sengngy Kouch · May 18, 2015 Oh, by the way, the swapping that I use is not a bubble sort method.The way my swapping method is:If you have ABCDE.you go to the first index, which is A.  Now swap the A with E.now you have EBCDA.Then the second index. which is B, now swap it. and you have EDCBA.Because you only have to loop through only half size of the string, which is the length of the string  = 5. and half of it is 5/2 = 2.We got two because integer doesn't get the decimal point. I dont know if this come across, but yeah. lol, Happy Coding!! Sengngy Kouch · May 18, 2015 No problem man! And the way you your program work is different from mines due to the fact that I used "String" and you use Char.  Both work great!Happy Coding! Gent Ymeri · May 18, 2015 Thank you! Even though I already solved the problem.Also, you are right, I should have written the code. The problem was that I didn't wrote the correct line of code for reversing the string, I knew the rest of the code how should it be done. it was  _strrev(text) which I didn't write for some reason during the lectures.Thank you for explaining me the things you did above. I also can see that I gave a wrong impression.. but, still thanks for taking your time and consideration to help me. the code you wrote about swapping, looks to me like kind bubble sort thing!? here is the code I wrote for the solution. Any feedback, would be appreciated. #include using namespace std;int main(){ char text[100]; cout << "Enter text:"; cin.getline(text, 100);_strrev(text); cout << "The text in reverse order is:" << text<> input; // this allow you to get input from user. Sengngy Kouch · May 17, 2015 Hi there, nice to know you up here.First of all, instead asking people to give you the solution, why don't you show us what you got so far?Not to be rude, but if you are going to just ask people to give you the whole solution, you might consider dropping this major as it is going to be a lot more difficult.===================================================================Alright, enough said.1. I don't know if you already know how to get input from user. so here is how:First, make sure you have type #include in your file.Then.``string input;cout input; // this allow you to get input from user.``Remember that this only allow user to input a single string. Without any white space.  2.Print the entered text in reversed order.First of all, I think you should know how to use For loop, don't  you?and do you know how to use substr ?The main idea is to go through half way of the  "for loop"  and swap the right character with left character.Example.   your string is "ABCDE"so you need loop through the string half way by:``for ( int i = 0; i< input.length() / 2; i++){ // do the swap here.}``swapping is easy when you master it.``string temp;temp = leftSubstring;leftSubstring = rightSubString; // note: this is just a pseudo code, you need to use substr here.rightSubString = temp;``3.Replacing the case of the letter is easy.you need to type :  #include  then use thing line of code:``transform(input.begin(), input.end(), input.begin(), ::tolower); // from upper to lower.transform(input.begin(), input.end(), input.begin(), ::toupper); // from lower to upper.``I hope this help.
• 1

## C++

105,020 followers