Thread: convert an string within a struct

  1. #1

    Question convert an string within a struct

    Here's the struct:
    typedef struct __dun_request
    char to_dun_msgid[12];
    char to_dun_rc[2];
    char to_dun_send_len[4];
    char to_dun_rec_len[4];
    char to_dun_filler[12];
    char to_dun_userdata[6000];
    } dun_request_def;

    I pass to_dun_send_length = "0034".

    atoi(dun_from_buf.fr_dun_rec_len) returns 12320

    any ideas why?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    >char to_dun_send_len[4];
    is 4 bytes long,
    is 5 bytes long. 4 you can see, the last is the null terminator. The code is therefore bugged, as you can't use the array as a string.

    And I trust you used strcpy() (or similar) to populate the array, as opposed to a straight assign like you showed?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 10:24 AM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM