473,569 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use memcpy to copy a structure into the buffer

3 New Member
hi,
struct msg
{
struct header ht;
char buf[4096];
}*mt;

struct tlv
{
uint32_t tag;
uint32_t len;
char val[256];
};
struct tlvlist
{
uint32_t msglen;
struct tlv *source;
struct tlv *msgkey;
struct tlv *delim;
struct tlv *oper[max];
};

struct tlv *att;
struct tlvlist *attlist,*attli st1;
source have some data as tag,length,valu e.
can any one please help in using memcpy function to copy the data in the
source structure to the char buf[4096] which is in struct msg.

thanks
samba
Apr 3 '07 #1
2 11894
Savage
1,764 Recognized Expert Top Contributor
hi,
struct msg
{
struct header ht;
char buf[4096];
}*mt;

struct tlv
{
uint32_t tag;
uint32_t len;
char val[256];
};
struct tlvlist
{
uint32_t msglen;
struct tlv *source;
struct tlv *msgkey;
struct tlv *delim;
struct tlv *oper[max];
};

struct tlv *att;
struct tlvlist *attlist,*attli st1;
source have some data as tag,length,valu e.
can any one please help in using memcpy function to copy the data in the
source structure to the char buf[4096] which is in struct msg.

thanks
samba
Hi,samba

I think that it should be like:

memcpy(mt.buf,s ource)
Apr 3 '07 #2
gpraghuram
1,275 Recognized Expert Top Contributor
HI,
Use memcpy this way
Expand|Select|Wrap|Line Numbers
  1. memcpy(&buf,&str,sizeof(str));
  2.  
For more info refer to this link
Link

Thanks
Raghuram
Apr 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2812
by: cylin | last post by:
Dear all, When I use memcpy second time, it seems to be no use. There should be two "Hello,world!" strings in this buffer. I don't know what's wrong? Please help, thanks. Regards, cylin. ----------------------------------------------
15
38113
by: Sourcerer | last post by:
Hi all. Can I do this to duplicate the contents of struct a in struct b struct myStruct a, b, *aptr, *bptr; aptr = a; bptr = b; Do something to initialize contents of structure a memcpy(bptr, aptr, sizeof(myStruct));
14
3183
by: ishmael4 | last post by:
hello! i've go two structures: --cut here-- const unsigned int max_pkg_data=5000; typedef struct pkg_ { short int info; short int size;
6
36233
by: EOS | last post by:
I guess what I want to do is best explain via the codes here; Byte byteA = new Byte; Byte byteB = new Byte; .... .... .... Now I want to copy 4 bytes from certain portion of the byteA array.
16
2780
by: Jeff | last post by:
Im trying to memcpy a buffer from a filled in simple structure. When I memcpy and then print the resulting buffer, I see 7 locations that have junk before my data starts. My data structure is: struct command_pkt { char command_num; char command; }; typedef command_pkt COMMAND;
6
36539
by: Juergen Wohnich | last post by:
Hello, i want to do store int variablen into a char Buffer. Like this: char Buffer; int b = 1447; int *pb; // pb deklariert als pointer auf int pb = &b; // & ist Adress operator, liefert Adresse von b memcpy( Buffer, pb, 4 );
18
21495
by: Mark | last post by:
Hi List, I want to write a function to copy some data out of a hardware buffer. The hardware can change the contents of this buffer without it being written to by my function. I want to use memcpy to unload the data. Do I need to specify the source data as volatile in this case? What is the correct syntax for specifying that the data...
4
3267
by: | last post by:
In C++ I use the memcpy function to copy a struct to a buffer, I have not been able to find a method to do this in C#. I will need to be able to do this for a struct with mixed types. Example as follows: public struct MyStruct { public int iOne;
14
2780
by: somenath | last post by:
Hi All, I am trying to understand the behavior of the memcpy and memmove. While doing so I wrote a program as mentioned bellow . #include<stdio.h> #include<stdlib.h> #include<string.h> #define SIZE_OF_DST 3 int main(void)
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.