Thread: convert an alpha character from commandline to equivalent ASCII integer

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    6

    convert an alpha character from commandline to equivalent ASCII integer

    I am trying to read an input from commandline e.g ./make DOOD
    Specifically, I want to loop through DOOD and take the ASCII value of character "D" convert it to a variable say V and add V to a number say 5 and output a character G which is the sum of ascii values " V+5" so that I have

    G = V+5
    printf("%c", G)

    Thanks

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    505
    A char already is a small integer. so char ch = 'D' and char ch = 68 are exactly equivalent. You can manipulate chars by adding or subtracting values from them, just like integers, and you can convert to and from int. You can even multiply or divide (though it's hard to see where that would make sense).
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    6
    Thanks Malcom. Appreciate it. My programme now works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert integer to character
    By Swoorup in forum C++ Programming
    Replies: 20
    Last Post: 11-28-2011, 04:53 AM
  2. Replies: 4
    Last Post: 02-21-2009, 03:12 PM
  3. How do I make a integer into a ascii character?
    By AsleeKaizoku in forum C Programming
    Replies: 5
    Last Post: 01-23-2008, 11:30 PM
  4. Replies: 1
    Last Post: 07-31-2002, 10:49 AM