第一次遇到 Aborted (核心已转储) 错误

代码如下

#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 (核心已转储)

发布了9 篇原创文章 · 获赞 2 · 访问量 8564

猜你喜欢

转载自blog.csdn.net/hhl_work/article/details/103382059
今日推荐