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

How to find the ASCII value of the contents of a char variable?

P: 3
Hi,

I am a new programmer, and i want to do the following:

I read a string from the keyboard and i store it in a char variable. The string the user provides through the keyboard can be anything (numbers, letters, etc).

Then, i need to print on the screen the ASCII values of the string (for example, if i write ab through the keyboard, then i want my program to print 6566)
Nov 27 '10 #1

✓ answered by whodgson

It may be better to store what you get from the keyboard in a char array. Then using a loop get each individual char and convert it to ASCII code and place it in a second int array.

Share this Question
Share on Google+
3 Replies


100+
P: 542
It may be better to store what you get from the keyboard in a char array. Then using a loop get each individual char and convert it to ASCII code and place it in a second int array.
Nov 28 '10 #2

100+
P: 1,059
Use this code

Expand|Select|Wrap|Line Numbers
  1. char c;
  2. printf("%d",c)
Nov 28 '10 #3

P: 3
Thanks whodgson, it worked!
Nov 28 '10 #4

Post your reply

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