|
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>
#include <string.h>
#define LEN_INPUT1 11
#define LEN_INPUT2 11
int main(void) {
// case 1
char s1[LEN_INPUT1];
char s2[LEN_INPUT2];
scanf("%s %s", s1, s2);
strcat(s1, s2);
printf("%s", s1);
// case 2
char s1[LEN_INPUT1];
char s2[LEN_INPUT2];
char s3[21];
scanf("%s %s", s1, s2);
int i;
for (i = 0; s1[i] != '\0'; i++) {
s3[i] = s1[i];
}
for (int j = 0; s2[j] != '\0'; j++) {
s3[i] = s2[j];
i++;
}
s3[i] = '\0';
printf("%s", s3);
return 0;
}
|
cs |
case 1 : strcat 함수를 이용하여 s1, s2를 연결한 값을 출력한다.
- strcat은 s2를 s1에 연결하고 널 문자를 붙여 반환한다.
case 2 : s3에 문자들을 연결하여 끝에 널 문자를 붙여 출력한다.
'C > 코딩 기초 트레이닝' 카테고리의 다른 글
| 이어 붙인 수 (0) | 2024.02.05 |
|---|---|
| 코드 처리하기 (0) | 2024.02.05 |
| 더 크게 합치기 (0) | 2024.02.04 |
| 조건 문자열 (0) | 2024.01.12 |
| 문자 리스트를 문자열로 변환하기 (0) | 2024.01.12 |