convert an alpha character from commandline to equivalent ASCII integer

This is a discussion on convert an alpha character from commandline to equivalent ASCII integer within the C Programming forums, part of the General Programming Boards category; I am trying to read an input from commandline e.g ./make DOOD Specifically, I want to loop through DOOD and ...

  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
    333
    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.
    http://www.malcolmmclean.site11.com/www

  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, 03:53 AM
  2. Replies: 4
    Last Post: 02-21-2009, 02: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, 10:30 PM
  4. Convert a character to integer (ex '1' to 1)
    By VanJay011379 in forum C++ Programming
    Replies: 11
    Last Post: 03-18-2003, 12:14 AM
  5. Replies: 1
    Last Post: 07-31-2002, 10:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21