ASCII codes

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

Join Date: Oct 2007
Posts: 3
Reputation: mstrmnd2008 is an unknown quantity at this point 
Solved Threads: 0
mstrmnd2008 mstrmnd2008 is offline Offline
Newbie Poster

ASCII codes

 
0
  #1
Oct 11th, 2007
I am doing a c++ assignment and just need a little help. I would just like to know how to get the ASCII code number after inputing an ASCII character. The user of this program should be able to input an uppercase letter and recieve the ASCII code value and its corresponding lower case letter with ASCII code value.

Thanks
Last edited by mstrmnd2008; Oct 11th, 2007 at 10:32 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
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: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: ASCII codes

 
0
  #2
Oct 11th, 2007
just output the character as an integer, you might have to typecast it depending on what functions you use to display 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  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: ASCII codes

 
0
  #3
Oct 12th, 2007
> I would just like to know how to get the ASCII code number after inputing an ASCII character.
a. change the locale of std::cin from the default locale to one using an ASCII char set.
b. read the char entered by the user
c. convert it to an int to get the ascii code point.
d. use the tolower member of the ctype facet of the locale imbued by std::cin to get the lower case character
or check for the code point to be in the range for upper case chars; add 32 to get the lower case char (works for ascii)
Last edited by vijayan121; Oct 12th, 2007 at 2:21 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,821
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 117
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: ASCII codes

 
0
  #4
Oct 12th, 2007
  1. char c;
  2. cin >> c;
  3. // verify c is an upper case letter
  4. c = c + 'a'-'A';
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: ASCII codes

 
0
  #5
Oct 12th, 2007
>a. change the locale of std::cin from the default locale to one using an ASCII char set.
>b. read the char entered by the user
>c. convert it to an int to get the ascii code point.
>d. use the tolower member of the ctype facet of the locale imbued by std::cin to get the lower case character
Somehow I get the impression that the assignment isn't expecting an internationalized solution.

>// verify c is an upper case letter
>c = c + 'a'-'A';
For future reference, while this works with ASCII, UTF-8, and UTF-16 (the encodings you're most likely to be dealing with), it's not strictly portable across all character sets. So keep in mind that while this may be how your teacher wants you to complete the assignment, isupper/islower and toupper/tolower provide a more robust solution.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC