How To Capitalize ALL Letters using Toupper function

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 13
Reputation: EngneerNitemare is an unknown quantity at this point 
Solved Threads: 0
EngneerNitemare EngneerNitemare is offline Offline
Newbie Poster

How To Capitalize ALL Letters using Toupper function

 
0
  #1
Oct 14th, 2009
I have the following code which I have been trying get to output ALL capital letters using the toupper function.

My code will build successfully, however all the letters are still lower case when ever I type.

PLEASE HELP ME UNDERSTAND WHAT I AM DOING WRONG!

The following is the code I have gotten to so far, but I need to know where to place the toupper function. Everytime I try to associate it with char c I do something wrong.
-------------------------------------------------------------------------------------------
  1. #include <stdio.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main (int argc, char *argv[], char **env)
  6. {
  7. char c, lastc = ' ' ;
  8. c = cin.get() ;
  9. do {
  10. cout.put(c) ;
  11.  
  12. c = cin.get() ;
  13. } while ( !cin.eof()) ;
  14. return 0;
  15. }
Last edited by WaltP; Oct 15th, 2009 at 11:09 pm. Reason: Added CODE tags -- with all the help about them, how could you miss using them????
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #2
Oct 14th, 2009
c = toupper(cin.get());
Or you could just do this:
cout << toupper(c);
Last edited by Ancient Dragon; Oct 14th, 2009 at 11:57 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 13
Reputation: EngneerNitemare is an unknown quantity at this point 
Solved Threads: 0
EngneerNitemare EngneerNitemare is offline Offline
Newbie Poster
 
0
  #3
Oct 15th, 2009
  1. #include <stdio.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main (int argc, char *argv[], char **env)
  6. {
  7. char c, lastc = ' ' ;
  8. [B]c = toupper(cin.get());[/B]
  9. do {
  10. cout.put(c) ;
  11. c = cin.get() ;
  12. } while ( !cin.eof()) ;
  13. return 0;
  14. }
Changed code,added "c = toupper(cin.get());" I believe I have tried this one before too. The program is still just simply typing out lowercase letters only!!!

This one is really frustrating me, I think that I am thinking too hard about it though.

Any other pointers???
Last edited by WaltP; Oct 15th, 2009 at 11:11 pm. Reason: And again, Added CODE tags -- look them up!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,980
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac
 
1
  #4
Oct 15th, 2009
Remove that line again and put it inside your loop. Put a cout << c; inside your loop and remove the other cin/cout statements.
So your loop-block should look like this:
  1. {
  2. c = toupper(cin.get());
  3. cout << c;
  4. }

also code-tags. Learn to use them.
Last edited by niek_e; Oct 15th, 2009 at 3:43 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 71
Reputation: tkud is an unknown quantity at this point 
Solved Threads: 15
tkud's Avatar
tkud tkud is offline Offline
Junior Poster in Training
 
-1
  #5
Oct 15th, 2009
You can also use this code snippet if you are confused..
char response[256];
cout<<"Enter a word.."<<endl;
---------------------------------------------
<cin.getline(response,256);
for(int i=0;i<response.length();i++){
response[i]=toupper(response[i]);
}>
-----------------------------------
This code converts 'response' to capital letters.
This is just for the knowing,anyway.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,980
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac
 
3
  #6
Oct 15th, 2009
Or a real C++ solution:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4.  
  5. struct upper {
  6. int operator() ( int c )
  7. {
  8. return toupper ( static_cast<unsigned char> ( c ) );
  9. }
  10.  
  11. };
  12.  
  13. int main(){
  14. std::string str = "";
  15. std::getline(std::cin, str);
  16. std::transform(str.begin(),str.end(),str.begin(),upper());
  17. std::cout << str;
  18. return 0;
  19. }

@tkud: code-tags: learn to use them
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 13
Reputation: EngneerNitemare is an unknown quantity at this point 
Solved Threads: 0
EngneerNitemare EngneerNitemare is offline Offline
Newbie Poster
 
-1
  #7
Oct 15th, 2009
All code given still has not worked..
Last edited by EngneerNitemare; Oct 15th, 2009 at 8:57 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #8
Oct 15th, 2009
Originally Posted by EngneerNitemare View Post
All code given still has not worked..
Post what you have tried instead of just crying about it.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 483 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC