Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Char to INT?

Char to INT?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi. I have a Char which containes a number, example 32. How do I convert the char to INT? char cTest[100]="32"; int iTest; now I want to convert the cTest to iTest so it's a integer instead of a char. Any function which can do this? thanks for any info.

    A G R 3 Replies Last reply
    0
    • A Anonymous

      Hi. I have a Char which containes a number, example 32. How do I convert the char to INT? char cTest[100]="32"; int iTest; now I want to convert the cTest to iTest so it's a integer instead of a char. Any function which can do this? thanks for any info.

      A Offline
      A Offline
      Alvaro Mendez
      wrote on last edited by
      #2

      atoi. int iTest = atoi(cTest); Regards, Alvaro


      Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

      N 1 Reply Last reply
      0
      • A Anonymous

        Hi. I have a Char which containes a number, example 32. How do I convert the char to INT? char cTest[100]="32"; int iTest; now I want to convert the cTest to iTest so it's a integer instead of a char. Any function which can do this? thanks for any info.

        G Offline
        G Offline
        Greven
        wrote on last edited by
        #3

        I think the easiest way would be to simply cast it... iTest = (int)cTest[i]; Wouldn't that work? :~ Programming in binary is as easy as 01 10 11.

        A C 2 Replies Last reply
        0
        • G Greven

          I think the easiest way would be to simply cast it... iTest = (int)cTest[i]; Wouldn't that work? :~ Programming in binary is as easy as 01 10 11.

          A Offline
          A Offline
          Alvaro Mendez
          wrote on last edited by
          #4

          Nope, it wouldn't work. Only the first character would be converted, and to it's ASCII value -- which is not what he needs. Regards, Alvaro


          Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

          G 1 Reply Last reply
          0
          • A Anonymous

            Hi. I have a Char which containes a number, example 32. How do I convert the char to INT? char cTest[100]="32"; int iTest; now I want to convert the cTest to iTest so it's a integer instead of a char. Any function which can do this? thanks for any info.

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            If you don't care about performance :) you can do:

            sscanf (cTest, "%d", &iTest);

            /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

            1 Reply Last reply
            0
            • G Greven

              I think the easiest way would be to simply cast it... iTest = (int)cTest[i]; Wouldn't that work? :~ Programming in binary is as easy as 01 10 11.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              :omg::wtf::omg::wtf::omg: I generally bring up a console project and test my theory if I'm not sure about advice I am about to give :-) Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002 Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

              1 Reply Last reply
              0
              • A Alvaro Mendez

                Nope, it wouldn't work. Only the first character would be converted, and to it's ASCII value -- which is not what he needs. Regards, Alvaro


                Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

                G Offline
                G Offline
                Greven
                wrote on last edited by
                #7

                Ah, my mistake... Didn't see the quote around 32... Thought he had an array of char's, not a string. :-O:rolleyes::-O Programming in binary is as easy as 01 10 11.

                1 Reply Last reply
                0
                • A Alvaro Mendez

                  atoi. int iTest = atoi(cTest); Regards, Alvaro


                  Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

                  N Offline
                  N Offline
                  Nitron
                  wrote on last edited by
                  #8

                  i'll second that. also, if you need a double, atof: double data = atof(szData); - Nitron


                  "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups