학습 내용 : strcpy() 함수의 내부적인 흐름을 학습합니다.

 

소스 코드 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <string.h>
 
#define        KOREA        "대한민국"
 
char* My_strcpy(char* dest, const char* src);
 
void main()
{
    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;
}

 

 

실행 화면 :