代码如下
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char *str = "qwe.er.tt.";
printf("str:%s\n", str);
printf("len:%d\n", strlen(str));
char *temp;
memcpy(temp, str, strlen(str));
printf("run:%d\n", __LINE__);
temp += (strlen(temp) - 1);
printf("str:%s\n", str);
printf("temp:%s\n", temp);
printf("run:%d\n", __LINE__);
free(temp);
printf("run:%d\n", __LINE__);
return 0;
}
$ gcc DianEndTest.c
$ ./a.exe
str:qwe.er.tt.
len:10
run:12
str:qwe.er.tt.
temp:.
run:17
Aborted (核心已转储)