✅ 목표 (Goal)

✅ 목차 (Index)

✅ strcpy 함수 예제

#pragma warning(disable: 4996)

#include <stdio.h>
#include <string.h>

int main() {

	// 요건 됨	
	//	char* dst= "Hello, ";
	//	printf("%s", dst);

	// 요건 안됨, Segmentation Fault 에러
	//	char* dst= "Hello, ";
	//	printf("%s", dst);	
	//	strcpy(dst,  "World !!"); 

	// 배열은 당연히 되는데.. 또 오로지 배열만 되는건 아니다.
	//	char dst[]= "Hello, ";
	//	char src[]= "World ";
	//	strcpy(dst,  src);
	//	printf("%s", dst);

	// 앞의 인자만 배열이면 된다.
	//	char dst[]= "Hello";
	//	strcpy(dst, "xxx");
	//	printf("%s", dst);

	// 굳이 포인터를 쓰려고 하면 아래와 같이 쓰면 되기는 된다.	
	
	char* dst = "Hello";
	int tmp_addr = 0;  // 임시로 변수를 하나 만들고

	dst = (char*)&tmp_addr; // &변수의 주소 알아내서, char*로 강제 형변환한 이후에
	strcpy(dst, "yyy");
	printf("%s", dst);

	return 0;
}

1.png

✅ 참조 (Ref.)

▼ strcpy와 세그먼테이션 폴트

https://yyman.tistory.com/96