-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.c
More file actions
108 lines (93 loc) · 2.3 KB
/
main.c
File metadata and controls
108 lines (93 loc) · 2.3 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
#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("sizes are equal\n\n");
}
//두 개의 파일 블락 수를 비교하는 함수 작성
void blockcmp(){
printf("block compare\n");
if((int)stat1.st_blocks > (int)stat2.st_blocks)
printf("text1 is more than text2\n\n");
else if((int)stat1.st_blocks < (int)stat2.st_blocks)
printf("text2 is more than text1\n\n");
else
printf("blocks are equal\n\n");
}
//두 개의 파일 수정 날짜를 비교하는 함수 작성
void datecmp(){
printf("date compare\n");
if(time1->tm_mon > time2->tm_mon){
printf("text2 is early\n\n");
}
else if(time1->tm_mon < time2->tm_mon){
printf("text1 is early\n\n");
}
else if(time1->tm_mday > time2->tm_mday){
printf("text2 is early\n\n");
}
else if(time1->tm_mday < time2->tm_mday){
printf("text1 is early\n\n");
}
else{
printf("same date\n\n");
}
}
//두 개의 파일 수정 시간을 비교하는 함수 작성
void timecmp(){
printf("time compare\n");
if(stat1.st_mtime < stat2.st_mtime){
printf("text1 is early\n");
}
else if(stat1.st_mtime > stat2.st_mtime){
printf("text2 is early\n");
}
else{
printf("same time\n");
}
}