Language/C
[따배씨] 9.11 헤더 파일 만들기
migrationArc
2021. 6. 3. 23:09
따배씨 - 따라하며 배우는 C언어
9강 함수
9.11 헤더 파일 Header Files 만들기
- 헤더 파일을 만들어서 코드를 여러개의 파일로 분리하여 반복사용하는 것이 효율적
#include <stdio.h>
void print_hello(){
printf("Hello\n");
}
void print_hi(){
printf("Hi\n");
}
void print_str(char* str){
printf("%s\n", str);
}
int main(){
print_hello();
print_hi();
print_hello();
print_hi();
print_str("No one lives forever.");
print_str("Valar morghulis");
return 0;
}
#include <stdio.h>
#include "my_print_functions.h"
int main(){
print_hello();
print_hi();
print_hello();
print_hi();
print_str("No one lives forever.");
print_str("Valar morghulis");
printf("Hello");
return 0;
}
- main.c
- include 된 header 파일에 stdio.h 가 include 되었지만, main.c 에서 printf 함수를 사용 하려면 stdio.h 헤더를 다시 include 해주어야함
- header 파일에 include 한것은 파일 범위에서만 유효
#fndef my_print_functions_h
#define my_print_functions_h
void print_hello(void);
void print_hi(void);
void print_str(char* str);
#endif /* my_print_functions_h */
- my_print_functions.h
- prototype 선언
#include "my_print_functions.h"
#include <stdio.h>
void print_hello(){
printf("Hello\n");
}
void print_hi(){
printf("Hi\n");
}
void print_str(char* str){
printf("%s\n", str);
}
- my_print_function.c
- header 파일에 prototype을 선언한 함수를 작성
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
http://blog.naver.com/atelierjpro
실리콘 밸리의 프로그래머 : 네이버 블로그
안녕하세요! 홍정모 블로그에 오신 것을 환영합니다. 주로 프로그래밍 관련 메모 용도로 사용합니다. 강의 수강하시는 분들은 홍정모 연구소 카페로 오세요.
blog.naver.com
http://www.inflearn.com/course/following-c
홍정모의 따라하며 배우는 C언어 - 인프런 | 강의
'따배씨++'의 성원에 힘입어 새롭게 개발된 C 언어로 시작하는 프로그래밍 입문 강의입니다. '따배씨'와 함께 프로그래밍 인생을 업그레이드 해보세요., 따라하며 배우는 C언어 '따배씨++'의 성원
www.inflearn.com