본문 바로가기
Language/C언어

C058_헤더 파일 만들기

by OdOp 관리자 2024. 1. 17.
SMALL

헤더 파일을 만들어 보도록 하겠습니다. 

헤더 파일은 왜 필요한 것일까요???

예를 들어 저희가 코딩을 하는데에 있어 많은 헤더와 함수 선언이 필요하다고 가정해 봅시다. 

그렇게 되면 코딩 시작부터 굉장히 코드가 길어지겠죠???

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
...

 

위의 코드와 같이 main문 시작하기도 전에 굉장히 많은 코드를 작성하게 됩니다. 이를 한 줄로 줄이기 위해서 헤더 파일을 작성하는 것입니다.

 

헤더 파일

#ifndef MINE_H

  현재의 코드에 mine.h가 선언이 되어있지 않다면 '#endif'까지 선언을 해줍니다. 

# define MINE_H

  MINE_H를 만듭니다. 

# include <stdio.h>
# include <unistd.h>
# include <sys/time.h>
# include <stdlib.h>

필요한 헤더들을 작성합니다. 

#endif

작성을 완료했다면 끝을 냅니다.

#ifndef MINE_H
# define MINE_H

# include <stdio.h>
# include <unistd.h>
# include <sys/time.h>
# include <stdlib.h>

#endif

 

위의 작성된 것 외에 구조체, 함수와 같은 것들도 선언해 주어도 됩니다. 

LIST

'Language > C언어' 카테고리의 다른 글

C057_execve함수 설명  (1) 2024.01.15
C056_C언어에 환경 변수 사용하기  (1) 2024.01.14
C055_pipe 함수 사용하기  (1) 2024.01.13
C054_open 함수 사용하기  (0) 2024.01.12
C053_dup2 함수 사용하기  (0) 2024.01.11