type conversion

This is a discussion on type conversion within the C Programming forums, part of the General Programming Boards category; i hava 2 dimensional array that hold unsigned char like 234,678,87,23,23, and some thing like that. i want to convert ...

  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
    494
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    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 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
    Location
    Singapore
    Posts
    21,593
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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

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