-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.c
88 lines (75 loc) · 2.34 KB
/
main.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
struct stat stat1, stat2;
struct tm *time1, *time2;
void filestat1();
void filestat2();
void filetime1();
void filetime2();
void sizecmp();
void blockcmp();
void datecmp();
void timecmp();
int main(){
filestat1();
filestat2();
filetime1();
filetime2();
sizecmp();
blockcmp();
datecmp();
timecmp();
}
//파일 1의 정보를 가져오는 함수 작성
void filestat1() {
stat("text1", &stat1);
}
//파일 2의 정보를 가져오는 함수 작성
void filestat2() {
stat("text2", &stat2);
}
//파일 1의 시간 정보를 가져오는 함수 작성
void filetime1() {
time1 = localtime(&stat1.st_mtime);
}
//파일 2의 시간 정보를 가져오는 함수 작성
void filetime2() {
time2 = localtime(&stat2.st_mtime);
}
//두 개의 파일 크기를 비교하는 함수 작성
void sizecmp() {
printf("size compare\n");
if (stat1.st_size > stat2.st_size) printf("text1 is bigger\n\n");
else if (stat1.st_size < stat2.st_size) printf("text2 is bigger\n\n");
else printf("size are equal\n\n");
}
//두 개의 파일 블락 수를 비교하는 함수 작성
void blockcmp() {
printf("block compare\n");
if (stat1.st_blocks > stat2.st_blocks) printf("text1 is bigger\n\n");
else if (stat1.st_blocks < stat2.st_blocks) printf("text2 is bigger\n\n");
else printf("size are equal\n\n");
}
//두 개의 파일 수정 날짜를 비교하는 함수 작성
void datecmp() {
int tm2 = ((time2->tm_year + 1900) * 100 + (time2->tm_mon + 1) * 100) + time2->tm_mday;
time1 = localtime(&stat1.st_mtime);
int tm1 = ((time1->tm_year + 1900) * 100 + (time1->tm_mon + 1) * 100) + time1->tm_mday;
printf("date compare\n");
if (tm1 > tm2) printf("text2 is early\n\n");
else if (tm1 < tm2) printf("text1 is early\n\n");
else printf("same time\n\n");
}
//두 개의 파일 수정 시간을 비교하는 함수 작성
void timecmp(){
int tm1 = ((time1->tm_hour * 100) + time1->tm_min) * 100 + time1->tm_sec;
time2 = localtime(&stat2.st_mtime);
int tm2 = ((time2->tm_hour * 100) + time2->tm_min) * 100 + time2->tm_sec;
printf("time compare\n");
if (tm1 > tm2) printf("text2 is early\n\n");
else if (tm1 < tm2) printf("text1 is early\n\n");
else printf("same time\n\n");
}