Thread: type conversion

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    1

    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.




    regards
    mak.

  2. #2
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    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
    Location
    The edge of the known universe
    Posts
    39,661
    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
    Location
    Chappell Hill, Texas
    Posts
    2,332
    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.

    regards
    mak.
    Impossible

    (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 09:18 AM.
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Dino
    Impossible
    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, 08:38 PM