Structures in VC
-
you can use bitwise operators (>>, &, |, <<) to copy certain bytes from a buffer to the corresponding field in the structure. Er zit een korstje op mijn aars.
-
you cannot copy a whole group of varialbes into a structure, except at its initialization. the rest of the time, you'll have to point each member of the structure to affect it... this is because generally, the members of a structure may be by side, but not necessarily...
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
Try being more specific. How is the buffer declared? What's its content? In what format? How is the structure declared? Withouth such details, the answer can only be as vague as your question: Q: how do we copy data from a buffer to a structure? A: you extract pieces of data from the buffer and put them into the appropriate fields of the structure. :) -- jlr http://jlamas.blogspot.com/[^]
-
you can use bitwise operators (>>, &, |, <<) to copy certain bytes from a buffer to the corresponding field in the structure. Er zit een korstje op mijn aars.
-
Try being more specific. How is the buffer declared? What's its content? In what format? How is the structure declared? Withouth such details, the answer can only be as vague as your question: Q: how do we copy data from a buffer to a structure? A: you extract pieces of data from the buffer and put them into the appropriate fields of the structure. :) -- jlr http://jlamas.blogspot.com/[^]
-
That's a solution but you'll need to be sure that the data in the buffer has the same format as your structure. What I mean is that in your structure, the members will be aligned on a 8 bytes boundary (but you can change that). So, if it is not the case in your buffer, you will have some problems.
-
Try being more specific. How is the buffer declared? What's its content? In what format? How is the structure declared? Withouth such details, the answer can only be as vague as your question: Q: how do we copy data from a buffer to a structure? A: you extract pieces of data from the buffer and put them into the appropriate fields of the structure. :) -- jlr http://jlamas.blogspot.com/[^]
-
we have character data in our main buffer and also we need to pack two bytes of data from our main buffer into 1 byte of data in our small buffer.how we'll do this:mad:
hey hey hey, please calm down, otherwise, noboody will help you... moreover, you question is far from being clean... what are those buffers ? i've understood you had only one, and now, you talk of two buffers ! :omg: i think the best way to make us understand is to provide so little schemas (into <pre></pre> tags) and some code... explicit also you question clearly, with what you have, what you want, what don't work and what error messages are sent.
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
hey hey hey, please calm down, otherwise, noboody will help you... moreover, you question is far from being clean... what are those buffers ? i've understood you had only one, and now, you talk of two buffers ! :omg: i think the best way to make us understand is to provide so little schemas (into <pre></pre> tags) and some code... explicit also you question clearly, with what you have, what you want, what don't work and what error messages are sent.
TOXCCT >>> GEII power
[toxcct][VisualCalc]:(( actually i'm in office.....n m tensed as well...oki let me explain again that i've read a file and stored its data in buffer righttt! now i have to copy some specific bytes from that buffer to a structure.the thing is that the data in my file is stored in characters.means there is one character at each index.and i have to pick two characters at a time and store it in a structure....right now plzz tell me how we'l do this.......
-
:(( actually i'm in office.....n m tensed as well...oki let me explain again that i've read a file and stored its data in buffer righttt! now i have to copy some specific bytes from that buffer to a structure.the thing is that the data in my file is stored in characters.means there is one character at each index.and i have to pick two characters at a time and store it in a structure....right now plzz tell me how we'l do this.......
If you could post your structure, this would help a little bit more. You have to understand that we cannot see what's on your screen so we have to guess what you want to do with the little clues you gave us. Ok, in which 'format' you want to store this two characters ? Is it an integer or a string ? If it is a string, you can simply do that:
struct.MyString[0] = Buffer[Index]; struct.MyString[1] = Buffer[Index+1];
If it is an integer, you could do that:char Temp[3]; Temp[0] = Buffer[Index]; Temp[1] = Buffer[Index+1]; Temp[2] = '\0'; struct.MyInt = atoi(Temp);
If it doesn't help, try to be more specific and POST CODE !! -
:(( actually i'm in office.....n m tensed as well...oki let me explain again that i've read a file and stored its data in buffer righttt! now i have to copy some specific bytes from that buffer to a structure.the thing is that the data in my file is stored in characters.means there is one character at each index.and i have to pick two characters at a time and store it in a structure....right now plzz tell me how we'l do this.......
Nadia, Could you please provide us your structure prototype?. And I also intersteded in your buffer data?. How they are categorised/delimited from each item? What do you mean by big buffer and small buffer :)? " Action without vision is only passing time, Vision without action is merely day dreaming, But vision with action can change the world " - Words from Nelson Mandela Thanks & Regards, Gopalakrishnan
-
Nadia, Could you please provide us your structure prototype?. And I also intersteded in your buffer data?. How they are categorised/delimited from each item? What do you mean by big buffer and small buffer :)? " Action without vision is only passing time, Vision without action is merely day dreaming, But vision with action can change the world " - Words from Nelson Mandela Thanks & Regards, Gopalakrishnan
enough !!! :mad: there are too many posts on CP Forums that are just reposts of what's just been said right before... Cedric and I already asked what you just posted there. did you bother read the answers before making yours ?
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
enough !!! :mad: there are too many posts on CP Forums that are just reposts of what's just been said right before... Cedric and I already asked what you just posted there. did you bother read the answers before making yours ?
TOXCCT >>> GEII power
[toxcct][VisualCalc]:) What you understood by all your post...:laugh: " Action without vision is only passing time, Vision without action is merely day dreaming, But vision with action can change the world " - Words from Nelson Mandela Thanks & Regards, Gopalakrishnan
-
That's a solution but you'll need to be sure that the data in the buffer has the same format as your structure. What I mean is that in your structure, the members will be aligned on a 8 bytes boundary (but you can change that). So, if it is not the case in your buffer, you will have some problems.
-
Alignment can be adjusted and by default uses natual alignment up to 8 byte PODs. VC doesn't use 8 byte alignment. Tim Smith I'm going to patent thought. I have yet to see any prior art.
Tim Smith wrote: Alignment can be adjusted and by default uses natual alignment up to 8 byte PODs Yes, that's what I said :). Tim Smith wrote: VC doesn't use 8 byte alignment :doh: Err, pretty sure that it does. I had a bug two years ago because of that (loading data from a file and memcpy it to a struct) and I spent a lot of time to solve it. And it was because of the member struct alignement that was to 8 by default.