convert an string within a struct

This is a discussion on convert an string within a struct within the C Programming forums, part of the General Programming Boards category; 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]; } ...

  1. #1
    Unregistered
    Guest

    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
    Posts
    6,231
    >char to_dun_send_len[4];
    is 4 bytes long,
    >"0034"
    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, 02:10 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 09:24 AM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM

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