-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
148 lines (132 loc) · 3.33 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#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(const char *filename);
void filestat2(const char *filename);
void filetime1();
void filetime2();
void sizecmp();
void blockcmp();
void datecmp();
void timecmp();
int main(){
const char *filename1="text1";
const char *filename2="text2";
filestat1(filename1);
filestat2(filename2);
filetime1();
filetime2();
sizecmp();
blockcmp();
datecmp();
timecmp();
return 0;
}
//파일 1의 정보를 가져오는 함수 작성
void filestat1(const char *filename){
if(stat(filename,&stat1)==-1)
{
perror("stat1");
}
return;
}
//파일 2의 정보를 가져오는 함수 작성
void filestat2(const char *filename){
if(stat(filename,&stat2)==-1)
{
perror("stat2");
}
}
//파일 1의 시간 정보를 가져오는 함수 작성
void filetime1(){
time1=localtime(&stat1.st_mtime);
if(time1==NULL)
{
perror("localtime1");
}
return;
}
//파일 2의 시간 정보를 가져오는 함수 작성
void filetime2(){
time2=localtime(&stat2.st_mtime);
if(time2==NULL)
{
perror("localtime2");
}
return;
}
//두 개의 파일 크기를 비교하는 함수 작성
void sizecmp(){
printf("size compare\n");
if( ((stat1.st_size) - (stat2.st_size)) > 0 )
printf("text1 is bigger\n");
else if( ((stat1.st_size) - (stat2.st_size)) < 0 )
printf("text2 is bigger\n");
else if( (stat1.st_size) - (stat2.st_size) == 0 )
printf("sizes are equal.\n");
}
//두 개의 파일 블락 수를 비교하는 함수 작성
void blockcmp(){
printf("\nblock compare\n");
blkcnt_t blkcnt1 = stat1.st_blocks;
blkcnt_t blkcnt2 = stat2.st_blocks;
if (blkcnt1 > blkcnt2)
{
printf("%s is bigger\n", "text1");
}
else if (blkcnt1 < blkcnt2)
{
printf("%s is bigger\n", "text2");
}
else
{
printf("sizes are equal\n");
}
}
//두 개의 파일 수정 날짜를 비교하는 함수 작성
void datecmp(){
printf("\ndate compare\n");
//text1
int day1 = localtime(&stat1.st_mtime)->tm_mday;
int month1 = localtime(&stat1.st_mtime)->tm_mon;
int year1 = localtime(&stat1.st_mtime)->tm_year;
//text2
int day2 = localtime(&stat2.st_mtime)->tm_mday;
int month2 = localtime(&stat2.st_mtime)->tm_mon;
int year2 = localtime(&stat2.st_mtime)->tm_year;
if (year1 > year2)
printf("text2 is early\n");
else if (year1 < year2)
printf("text1 is early\n");
else {
if (month1 > month2)
printf("text2 is early\n");
else if (month1 < month2)
printf("text1 is early\n");
else {
if (day1 > day2)
printf("text2 is early\n");
else if (day1 < day2)
printf("text1 is early\n");
else
printf("same date\n");
}
}
printf("\n");
}
//두 개의 파일 수정 시간을 비교하는 함수 작성
void timecmp(){
printf("time compare\n");
time_t diff = difftime(stat1.st_mtime, stat2.st_mtime);
if (diff > 0)
printf("text2 is early\n");
else if (diff < 0)
printf("text1 is early\n");
else
printf("same time\n");
printf("\n");
}