058. 문자열을 복사하는 함수 만들기058. 문자열을 복사하는 함수 만들기

Posted at 2011. 1. 30. 17:52 | Posted in Computer/초보자를 위한 C 언어 300제
#include <stdio.h>

#define KOREA "대한민국"

char* My_strcpy( char* dest, const char* src );

void main( void )
{
	char string[100];

	My_strcpy( string, KOREA );

	puts( string );		// 대한민국을 출력
}

char* My_strcpy( char* dest, const char* src )
{
	if( dest == (int)NULL || src == (int)NULL )
	{
		if( *dest != (int)NULL ) *dest =(int)NULL;
		return NULL;
	}

	do
	{
		*dest++ = *src;
	}
	while( *src++ != (int)NULL );

	return dest;
}
//