단순 구조체포인터인데,, free() 질문 드려요
세여닝
2023.04.01
질문 제목 : 단순 구조체포인터인데,, free() 질문 드려요메모리할당하고 free()로 헤재 하려고 하는데, 오류가 발생합니다.질문 내용 : 메모리할당하고 free()로 헤재 하려고 하는데, 오류가 발생합니다.
#include stdio.h
#include stdlib.h
#include string.h
struct person{
char* name;
int age;
char* address;
};
int main(){
struct person* aa;
aa = (struct person*)malloc(sizeof(struct person));
aa-address = (char*)malloc(sizeof(15));
aa-name = (char*)malloc(sizeof(15));
strcpy(aa-name, lee);
strcpy((*aa).address, ogeun);
aa-age = 23;
printf(%s %d %s\n, aa-name, aa-age, aa-address);
free(aa-address);
free(aa-name);
free(aa);
}
printf까지 잘 찍힙니다..
free만 하려고하면 오류가 발생하네요..
(툴은 vc++ 2005 입니다.)
왜 오류가 나는지.. 알려주시면 감사하겠습니다.