Results 1 to 6 of 6

Thread: Need example...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    231

    Need example...

    In Whinge's post, he created a ucpData structure like so:

    Code:
    unsigned char cData[] = 
    { SNIFF_PACKET_H1,SNIFF_PACKET_H2, 
    SNIFF_PACKET_XYZxyzHh,14, 
    (unsigned char)(iX >> 8),(unsigned char)(iX), 
    (unsigned char)(iY >> 8),(unsigned char)(iY), 
    (unsigned char)(iZ >> 8),(unsigned char)(iZ), 
    0,0,0,0,0,0, 
    (unsigned char)(iH),0 
    };
    How would one add another chunk of data to this that is of type char[64] (for example) ..or really, any text string as opposed to what is basically integers in this example.

    And, how would this affect the size of the struct? Right now it is 14 ..would it be 15 if you added a string with 30 characters, or would it then be 44?

    I'm confused on this I've figured out how to send various types of data to SEQ using this example; however, I can't get anything but numbers to go through :/ .....big time newbie, I know.

  2. #2
    Registered User Mr. Suspicious's Avatar
    Join Date
    May 2002
    Posts
    667
    Each char is a number. A string (char[]) is actually an array of integers with the size of one byte each. With this in mind, I'm pretty sure you'll be able to work things out.
    Before asking anything read the pre-face section of http://www.smoothwall.org/download/p....9/doc.faq.pdf

    after you've read it, you know what to do next...




    "Stay alert! Trust noone! Keep your Lazers Handy! Have a nice day." -- Provided courtesy of the Computer. The Computer never lies.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    231
    ok...so this is valid? ..and WILL be the same length every time?

    Code:
    unsigned char cData[] = 
    { SNIFF_PACKET_H1,SNIFF_PACKET_H2, 
    SNIFF_PACKET_XYZxyzHh,78, 
    (unsigned char)(iX >> 8),(unsigned char)(iX), 
    (unsigned char)(iY >> 8),(unsigned char)(iY), 
    (unsigned char)(iZ >> 8),(unsigned char)(iZ), 
    0,0,0,0,0,0, 
    (unsigned char)(iH),0, (char)pChar->Name[64]
    };
    ...sorry for lame questions, I'm self taught and have used too many custom string classes in my life
    Last edited by Amadeus; 02-15-2003 at 11:43 PM.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    6
    Your code will take the 65th element in the Name array and stick it on the end of the cData array (not a struct). It will increase the size of the array by 1. You might get a compiler warning since you're casting to char and not unsigned char.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    231
    ok...so, then am I to do something like this? ..or is there an easier way?

    (or would this compile..havn't tried it.) ..perhaps someone can see what I'm failing miserably at trying to accomplish..hehe

    Code:
    //somewhere before we defined 'char buf[2]' as the word "ale"
    
    unsigned char cData[] = 
    { SNIFF_PACKET_H1,SNIFF_PACKET_H2, 
    SNIFF_PACKET_XYZxyzHh,17, 
    (unsigned char)(iX >> 8),(unsigned char)(iX), 
    (unsigned char)(iY >> 8),(unsigned char)(iY), 
    (unsigned char)(iZ >> 8),(unsigned char)(iZ), 
    0,0,0,0,0,0, 
    (unsigned char)(iH),0,buf[0], buf[1], buf[2]
    };

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    6
    That would be one way to do it. Keep in mind that you won't have a null terminator in your example. So if you try to pass your string to a C run-time function like strcpy by using something like &cData[18] then you're going to run into trouble. There are a few ways to accomplish what I think you are trying to accomplish. Another way would be to use the heap and allocate memory for the array plus whatever you needed to append your string to up front, including room for a null terminator. Then you could just strcpy your string to the end of that array. That way you only copy what you need.

    Compilers are pretty good these days about telling you what's wrong. Do you not have one available to you? In any event, this thread seems to be more general programming in nature, so this will be my last post on here. Feel free to PM me if you like.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

You may post new threads
You may post replies
You may post attachments
You may edit your posts
HTML code is Off
vB code is On
Smilies are On
[IMG] code is On