473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to use memcpy to copy a structure into the buffer

3
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,*attlist1;
source have some data as tag,length,value.
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 11828
Savage
1,764 Expert 1GB
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,*attlist1;
source have some data as tag,length,value.
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,source)
Apr 3 '07 #2
gpraghuram
1,275 Expert 1GB
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
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
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...
14
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
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
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: ...
6
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...
18
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...
4
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...
14
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> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.