(헤더)파일 포함
정의
- 지정된 헤더 파일이나 코드 파일의 내용을 현재 소스 코드의 해당
#include 지시어 위치에 그대로 복사해 붙여넣는 작업
표현
| 표현 |
설명 |
#include <파일명> |
표준 디렉터리에서 헤더 파일을 찾아 복사해 붙여넣는다. |
#include "파일명" |
현재 사용중인 디렉터리나 직접 지정한 경로의 소스 파일을 찾아 복사해 붙여넣는다. |
예시
헤더파일
1
2
3
4
5
6
| #include <stdio.h>
#include <stdlib.h>
int main(){
printf("printf 는 <stdio.h>의 함수입니다.\n");
}
|
1
2
| # 출력
printf 는 <stdio.h>의 함수입니다.
|
소스파일
1
2
3
4
5
6
7
8
| // 파일명 : source_sample.c
#include <stdio.h>
char* source_sample(){
printf("header_sample.c 파일이 실행되었습니다.\n");
char* return_value = "header sample 함수 리턴값";
return return_value;
}
|
1
2
3
4
5
6
7
8
9
| // 파일명 : main.c
#include <stdio.h>
#include "source_sample.c"
int main(){
char* header_sample_result = header_sample();
printf("header sample 함수로부터 리턴받은 값입니다. : %s\n", header_sample_result);
return EXIT_SUCCESS;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
| // 중간 파일 (소스코드만 예시로 붙여넣음)
#include <stdio.h>
char* source_sample(){
printf("header_sample.c 파일이 실행되었습니다.\n");
char* return_value = "header sample 함수 리턴값";
return return_value;
}
int main(){
char* header_sample_result = header_sample();
printf("header sample 함수로부터 리턴받은 값입니다. : %s\n", header_sample_result);
return EXIT_SUCCESS;
}
|
1
2
3
| # 출력
header_sample.c 파일이 실행되었습니다.
header sample 함수로부터 리턴받은 값입니다. : header sample 함수 리턴값
|
Reference
C 프로그래밍 (김형근, 곽덕훈, 정재화 공저)
C 프로그래밍 강의 (방송통신대 - 이병래)
Comments