Thread: type conversion

  1. #1
    Registered User
    Join Date
    Dec 2008

    type conversion

    i hava 2 dimensional array that hold unsigned char like 234,678,87,23,23, and some thing like that.

    i want to convert this to integer how is it posssible.


  2. #2
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    If it's a string then you can use atoi() function to do this.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.

    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Using strtol() would be better:
    - it detects overflow
    - it returns a pointer to the end of the converted string. Ideal if you're walking through a list of numbers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Katy, Texas
    Quote Originally Posted by makpandian View Post
    i hava 2 dimensional array that hold unsigned char like 234,678,87,23,23, and some thing like that.

    i want to convert this to integer how is it posssible.


    (edit, unless your value takes up two or more character positions, in which case, none of the string functions will work by themselves - you'll have to move the 2 or more bytes into another array, null terminate them, and then you can use a string function on it.
    Last edited by Dino; 12-13-2008 at 08:18 AM.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Quote Originally Posted by Dino
    Nah, it's possible with 10 bit bytes. But yeah, more likely it was just a typographical error when generating a random list of numbers by hand.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  2. type conversion
    By peterx in forum C Programming
    Replies: 3
    Last Post: 10-08-2005, 04:03 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 08:29 PM
  5. overloaded operator for type conversion error
    By mangoMan in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2004, 07:38 PM
Website Security Test