-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·122 lines (110 loc) · 2.63 KB
/
main.c
File metadata and controls
executable file
·122 lines (110 loc) · 2.63 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#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((int)stat1.st_size>(int)stat2.st_size){
printf("text1 is bigger\n\n");
}
else if((int)stat1.st_size<(int)stat2.st_size){
printf("text2 is bigger\n\n");
}
else
printf("sizes are equal\n\n");
}
//두 개의 파일 블락 수를 비교하는 함수 작성
void blockcmp(){
printf("block compare\n");
int size1 = (int)stat1.st_blocks;
int size2 = (int)stat2.st_blocks;
if(size1>size2){
printf("text1 is bigger\n\n");
}
else if(size1<size2){
printf("text2 is bigger\n\n");
}
else{
printf("sizes are equal\n\n");
}
}
//두 개의 파일 수정 날짜를 비교하는 함수 작성
void datecmp(){
int month2 = time2->tm_mon+1;
int day2 = time2->tm_mday;
time1 = localtime(&stat1.st_mtime);
int month1 = time1->tm_mon+1;
int day1 = time1->tm_mday;
printf("date compare\n");
if(month1 > month2)
printf("text2 is ealry\n\n");
else if(month1 < month2)
printf("text1 is ealry\n\n");
else{
if(day1 > day2)
printf("text2 is ealry\n\n");
else if(day1 < day2)
printf("text1 is ealry\n\n");
else
printf("same date\n\n");
}
}
//두 개의 파일 수정 시간을 비교하는 함수 작성
void timecmp(){
int hour1 = time1->tm_hour;
int min1 = time1->tm_min;
time2 = localtime(&stat2.st_mtime);
int hour2 = time2->tm_hour;
int min2 = time2->tm_min;
printf("time compare\n");
if(hour1 > hour2)
printf("text2 is early\n\n");
else if(hour1 < hour2)
printf("text1 is ealry\n\n");
else{
if(min1 > min2)
printf("text2 is ealry\n\n");
else if(min1 < min2)
printf("text1 is ealry\n\n");
else
printf("same time\n\n");
}
}