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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ciao
    New Member
    • Nov 2010
    • 3

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

    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)
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    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.

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      Use this code

      Code:
      char c;
      printf("%d",c)

      Comment

      • ciao
        New Member
        • Nov 2010
        • 3

        #4
        Thanks whodgson, it worked!

        Comment

        Working...