By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

How to change ASCII to Alphabet.

P: 1
i wonder how to change a number to alphabet. like ASCII to alphabet.

Expand|Select|Wrap|Line Numbers
  1.  
  2. int main()
  3.  
  4. int i;
  5. char c;
  6.  
  7. cout<<"write a while number"<<endl;
  8. cin>>i;
  9. c=i;
  10. cout<< c <<endl;
  11.  
  12. like this looks my code but it does not function properly as it should be.
  13.  
  14.  
  15.  
Sep 18 '10 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Well, if a char has a value of 'A', then if you assign the char to an int you can see the value of the int.

If you do this backwards, you have converted an int to a member of the alphabet.
Sep 18 '10 #2

Expert 100+
P: 2,396
@encryptor: I don't understand what you want to do. Please provide a simple example showing an input value and a corresponding output value.
Sep 19 '10 #3

P: 13
Your code set value to i from input (cin).

If you enter 65, and then set c = i, c holds 65 witch interprets as 'A' as character. "cout'ed" this gives "A" (as long as your PC does not have a very very strange coding table).

Execution would be:
Expand|Select|Wrap|Line Numbers
  1. write a while number
  2. 88<enter>
  3. X
  4.  
  5. or
  6.  
  7. write a while number
  8. 65<enter>
  9. A
  10.  
  11. and so on.
  12.  
Sep 19 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.