testDate.c, 파일 분할, 구조체
testDate.c
#include "date.h"
int main(void)
{
Date today = {2019, 7, 17};
Date birthday;
birthday.year = 2005;
birthday.month = 8;
birthday.day = 2;
printDate(&today);
printDate(&birthday);
return 0;
}
---
date.h
// 구조체 정의와 함수 선언이 들어감
#ifndef DATE_H // DATE_H가 정의되어있지 않다면
#define DATE_H // DATE_H를 가져다 붙인다. 2, 3, 13라인을 써주면 중복되지 않고 딱 한번만 붙게 해준다.
typedef struct date {
int year;
int month;
int day;
} Date;
void printDate(const Date* pd);
#endif
---
date.c
#include <stdio.h>
#include "date.h" // 같은 디렉토리에 있는 헤더파일을 찾는다.
void printDate(const Date* pd) {
printf("(%d/%d/%d)\n", pd->year, pd->month, pd->day);
}
---
#include "date.h"
int main(void)
{
Date today = {2019, 7, 17};
Date birthday;
birthday.year = 2005;
birthday.month = 8;
birthday.day = 2;
printDate(&today);
printDate(&birthday);
return 0;
}
---
date.h
// 구조체 정의와 함수 선언이 들어감
#ifndef DATE_H // DATE_H가 정의되어있지 않다면
#define DATE_H // DATE_H를 가져다 붙인다. 2, 3, 13라인을 써주면 중복되지 않고 딱 한번만 붙게 해준다.
typedef struct date {
int year;
int month;
int day;
} Date;
void printDate(const Date* pd);
#endif
---
date.c
#include <stdio.h>
#include "date.h" // 같은 디렉토리에 있는 헤더파일을 찾는다.
void printDate(const Date* pd) {
printf("(%d/%d/%d)\n", pd->year, pd->month, pd->day);
}
---
Comments
Post a Comment