Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   memcpy (http://www.go4expert.com/forums/memcpy-t20041/)

kami1219 10Nov2009 02:33



struct Buffer
  unsigned char pkt[4092];

struct Buffer *start;
start=(struct Buffer *)malloc(sizeof(struct Buffer));

unsigned char *pkt=(unsigned char *)malloc(4092*(sizeof(unsigned char)));
memcpy(&start->pkt,&pkt,len); //Where 'len' is the length of a packet that is stored in 'pkt'.

OUTPUT: Segmentation fault

This code does not show error when compiled but gives error on running.
I tried all in the following but it give same segmentation fault error every time.

It's a bit long code but I only need help in memcpy so that I have pasted the relevant lines. I need to copy the data that is in this 'pkt' to the 'start->pkt' of length 'len'. Appreciate any suggestions or help.

kami1219 10Nov2009 07:21

Re: memcpy
I did not understand it but when i use sizeof(pkt) instead of len, error does not come. What can be the reason. I want to copy data from 'pkt' to 'start->pkt' but of length len and sizeof(pkt) and len are not same.

All times are GMT +5.5. The time now is 07:09.