Distinguish whether the user is inputting a big letter or small

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

Join Date: Jan 2009
Posts: 147
Reputation: Phil++ is an unknown quantity at this point 
Solved Threads: 3
Phil++ Phil++ is offline Offline
Junior Poster

Distinguish whether the user is inputting a big letter or small

 
0
  #1
Jan 13th, 2009
So basically, I'm creating a switch statement that if the user enters a p or if they enter a P it will still work, any ideas? Thank you
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 147
Reputation: Phil++ is an unknown quantity at this point 
Solved Threads: 3
Phil++ Phil++ is offline Offline
Junior Poster

Re: Distinguish whether the user is inputting a big letter or small

 
0
  #2
Jan 13th, 2009
  1. switch (choice)
  2. {
  3. case 'p' || 'P': // do this
  4. break;
  5. case 's' || 'S': // do that
  6. }

won't work
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 950
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: Distinguish whether the user is inputting a big letter or small

 
0
  #3
Jan 13th, 2009
Convert the string to evaluate to lower case, then use it.
I prefer if-else statments, of stings for input.

For ASCII
In a loop of string size:
if (is upper case(91< && 64>)) then
    swap_case()

Swap function:
function swap_case(&character)
    character XOR 32
Last edited by MosaicFuneral; Jan 13th, 2009 at 6:55 pm.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Distinguish whether the user is inputting a big letter or small

 
0
  #4
Jan 13th, 2009
Or for a more reliable solution (ei for more than just ASCII) you can use tolower() and toupper() functions found in the cctype header

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: Distinguish whether the user is inputting a big letter or small

 
0
  #5
Jan 14th, 2009
Originally Posted by Phil++ View Post
  1. switch (choice)
  2. {
  3. case 'p' || 'P': // do this
  4. break;
  5. case 's' || 'S': // do that
  6. }

won't work
Indeed. 'p' || 'P' would expand to a bool value of true, as will 's' || 'S'. Compilers will generally refuse to compile the above, as particular cases of a switch statement are not allowed to be duplicated.

Try this instead;
  1. switch (choice)
  2. {
  3. case 'p':
  4. case 'P': // do this
  5. break;
  6. case 's':
  7. case 'S': // do that
  8. break;
  9. }
Right 98% of the time, and don't care about the other 3%.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC