I have read many suggested questions, but still cannot find out the answer. I know the content in buffer is a NULL terminated char array, and I want to copy it into a dynamic allocated char array. However, I kept getting segmentation fault from the strcpy function. Thanks for any help.
void myFunction()
{
char buffer[200];
// buffer was filled by recvfrom correctly, and can be printed out with printf()
char *message = malloc(200);
strcpy(message, buffer[1]);
}
////////////////
ok, so i tried strcpy(message, &buffer[1]); strcpy(message, buffer); but nothing worked!!
strcpy()should also be a[const] char *, the buffer. It is currently the second item of the buffer, achar.