Need a C Function to Convert a char string to int

This is a discussion on Need a C Function to Convert a char string to int within the C Programming forums, part of the General Programming Boards category; Hi all: I need a function to do the following. To take a char buffer of 14 octal bytes. These ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    Need a C Function to Convert a char string to int

    Hi all:

    I need a function to do the following. To take a char buffer of 14 octal bytes. These byes represent ASCII characters.

    Take the buffer and convert the last four bytes to an integer (bytes 10,11,12 and 13). The ETX (\003) is byte 14 on the end. buf2 is char buf2[14]

    buf2 contains \002\006\105\060\060\060\060\060\060\106\106\105\0 61\003

    For example:

    31 converts from \060\060\061\106 (i.e. 001F in Ascii)
    -31 converts from \106\106\105\061 (i.e. FFE1 in Ascii)
    0 converts from \060\060\060\060
    7 converts from \060\060\060\007
    15 convers from \060\060\060\106

    If you look at an ASCI to octal table it will make sense.

    I need the four chars in the last two byes to be converted to an interger.

    Thanks,
    DougC

  2. #2
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Just to give you a fighting chance before you get flamed to a crisp, read section 0.5 of the netiquete section of the programming FAQ.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    1

    There is a built in function

    variablename = atoi(tempvaribale);

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    There is a built in function
    variablename = atoi(tempvaribale);
    Yes, but atoi needs a null-terminated string and base 10, two conditions not met here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 09:54 PM
  2. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM

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