Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Algospot
- php
- web
- sorting
- Math
- 인프런
- server
- Cleancode
- DP
- BOJ
- dfs
- 생활코딩
- 따라하며 배우는 C언어
- JavaScript
- graph
- String
- Python
- C언어
- programmers
- C
- 백준
- 따라하면서 배우는 C언어
- Algorithm
- greedy
- udemy
- 종만북
- BFS
- BASIC
- 정수론
- 따배씨
Archives
- Today
- Total
몽상실현개발주의
[따배씨] 9.11 헤더 파일 만들기 본문
따배씨 - 따라하며 배우는 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을 선언한 함수를 작성
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
'Language > C' 카테고리의 다른 글
[따배씨] 9.13 포인터의 기본적인 사용 방법 (0) | 2021.06.03 |
---|---|
[따배씨] 9.12 포인터 Pointer 의 작동 원리 (0) | 2021.06.03 |
[따배씨] 9.10 피보나치 예제와 재귀 호출의 장단점 (0) | 2021.05.30 |
[따배씨] 9.9 이진수 변환 예제 (0) | 2021.05.30 |
[따배씨] 9.8 팩토리얼 예제 (0) | 2021.05.30 |
Comments