Strlen causes segfault
c
Solution
It looks like your arguments to `memcpy` are the wrong way around. The first argument is the destination, the second argument is the source. It looks like you want to copy the contents of `restP` into `str`.
memcpy(str, restP, strlen(restP) + 1);
I've added one to the length of `restP` so that the null character is copied too (which isn't counted as part of `strlen`. You don't need to subtract one from `strlen` unless:
You know `str` is long enough and it is initialised to zero so that any appropriately sized string that is copied into it will be terminated by a null character.
You don't want to copy the last character of the source string.
Problem
I have problem with understanding `strlen` and/or `memcpy`. This is the snippet: ``` char * restP; char * str; //this returns a pointer restP = strrstr (input_buffer, "pointer"); //this prints this pointer printf("%p\n", restP); str = malloc( 50000); //this is wrong, restP is a pointer to a sring; i can print it with printf("%s", restP); it just a part of input_buffer memcpy(restP, str, strlen(restP)-1 ); ``` strlen(restP) gives me an error - `segmentation fault.` Maybe someone could give me a clue what am I doing wrong.