Computer/초보자를 위한 C 언어 300제
058. 문자열을 복사하는 함수 만들기
Theo Kim
2011. 1. 30. 17:52
#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;
}