我在理解strlen
和/或memcpy
时遇到问题。 这是片段:Strlen导致段错误
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)给我一个错误 - segmentation fault.
也许有人可以给我一个线索我在做什么错。
你确定它是'strlen'而不是'memcpy'吗? – dreamlax
您的第一个2个memcpy参数被反转 –
您没有为restP变量分配内存。 –