Char[] to Int

This is a discussion on Char[] to Int within the C++ Programming forums, part of the General Programming Boards category; Looking to convert char Num[5] into an integer, is there such a way? And if not, is there a way ...

  1. #1
    Epo is offline
    Registered User
    Join Date
    Jun 2003

    Char[] to Int

    Looking to convert char Num[5] into an integer, is there such a way?
    And if not, is there a way to start off with a string-ish type variable (to read from a textbox) and end up with an integer (for mathematical calculations)?


  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Ontario, Canada
    Look up sscanf and atoi.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    It's similar to the method described in the FAQ. Just use the char arrays instead of strings.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    As what you ask is more commonly used in C, read this FAQ entry. strtol() is the "safest" way.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  4. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM

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