-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.c
More file actions
146 lines (130 loc) · 3.48 KB
/
main.c
File metadata and controls
146 lines (130 loc) · 3.48 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
struct stat stat1,stat2;
struct tm *time1, *time2;
void filestat1(void);
void filestat2(void);
void filetime1(void);
void filetime2(void);
void sizecmp(void);
void blockcmp(void);
void datecmp(void);
void timecmp(void);
int main(void)
{
filestat1();
filestat2();
filetime1();
filetime2();
sizecmp();
blockcmp();
datecmp();
timecmp();
}
//파일 1의 정보를 가져오는 함수 작성
void filestat1(void)
{
if(stat("./text1", &stat1) == -1) {
perror("Error occurred while reading filestat of text1");
exit(1);
}
// printf("%ld\n",stat1.st_size);
}
//파일 2의 정보를 가져오는 함수 작성
void filestat2(void)
{
if(stat("./text2", &stat2) == -1) {
perror("Error occurred while reading filestat of text2");
exit(1);
}
// printf("%ld\n",stat2.st_size);
}
//파일 1의 시간 정보를 가져오는 함수 작성
void filetime1(void)
{
time1 = malloc(sizeof(struct tm));
localtime_r(&stat1.st_mtime, time1);
// printf("modified at %d/%d %d:%d\n", time1->tm_mon, time1-> tm_mday, time1->tm_hour,time1->tm_min);
}
//파일 2의 시간 정보를 가져오는 함수 작성
void filetime2(void)
{
time2 = malloc(sizeof(struct tm));
localtime_r(&stat2.st_mtime,time2);
// printf("modified at %d/%d %d:%d\n", time2->tm_mon, time2-> tm_mday, time2->tm_hour,time2->tm_min);
}
//두 개의 파일 크기를 비교하는 함수 작성
void sizecmp(void)
{
// if(stat("./text1", &stat1) == -1) {
// perror("Error occurred while reading filestat of text1");
// }
// if(stat("./text2", &stat2) == -1) {
// perror("Error occurred while reading filestat of text2");
// }
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");
return;
}
//두 개의 파일 블락 수를 비교하는 함수 작성
void blockcmp(void)
{
printf("block compare\n");
if(stat1.st_blocks > stat2.st_blocks)
printf("text1 is bigger\n");
else if(stat1.st_blocks < stat2.st_blocks)
printf("text2 is bigger\n");
else
printf("sizes are equal\n");
printf("\n");
}
//두 개의 파일 수정 날짜를 비교하는 함수 작성
void datecmp(void)
{
printf("date compare\n");
if(time1->tm_mon < time2->tm_mon){
printf("text1 is early\n\n");
}else if(time1->tm_mon > time2->tm_mon){
printf("text2 is early\n\n");
}else{
if(time1->tm_mday < time2->tm_mday){
printf("text1 is early\n\n");
}else if(time1->tm_mday > time2->tm_mday){
printf("text2 is early\n\n");
}else{
printf("same date\n\n");
}
}
return ;
}
//두 개의 파일 수정 시간을 비교하는 함수 작성
void timecmp(void)
{
printf("time compare\n");
if(time1->tm_hour < time2->tm_hour)
printf("text1 is early\n\n");
else if(time1->tm_hour > time2->tm_hour)
printf("text2 is early\n\n");
else{
if(time1->tm_min < time2->tm_min) {
printf("text1 is early\n\n");
}else if(time1->tm_min > time2->tm_min) {
printf("text2 is early\n\n");
}
else {
printf("same time\n\n");
}
}
free(time1);
free(time2);
return;
}