| | |
ASCII codes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Solved Threads: 0
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
Thanks
Last edited by mstrmnd2008; Oct 11th, 2007 at 10:32 pm.
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
> 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)
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.
C++ Syntax (Toggle Plain Text)
char c; cin >> c; // verify c is an upper case letter c = c + 'a'-'A';
>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.
>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.
![]() |
Similar Threads
- How to convert Scancode to ASCII. (C)
- print corresponding ascii for letters (Assembly)
- Display image from a database get me ascii codes (ASP)
- Prog to list ASCII codes (beginners' stuff) (C)
Other Threads in the C++ Forum
- Previous Thread: Issues with double linked list
- Next Thread: Game Programming for Slot machines
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






