본문 바로가기

프로그래밍/C언어

[DGPD][C언어] 문자열 연결 함수 strcat 만들기.

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
#include <stdio.h>
 
char* myStrcat(char* destination, const char* source)
{
    while (*destination != '\0')
    {
        destination++;
    }
 
    while (*source != '\0')
    {
        *destination = *source;
        destination++;
        source++;
    }
    *destination = '\0';
 
    return destination;
}
 
int main()
{
    char str[80= "these ";
    myStrcat(str, "strings ");
    myStrcat(str, "are ");
    myStrcat(str, "concatenated.");
    printf("str: %s\n", str);
 
    return 0;
}
 
cs