Guest User

Untitled

a guest
Apr 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <unistd.h>
  5. #include <time.h>
  6.  
  7.  
  8. struct stat stat1, stat2;
  9. struct tm *time1, *time2;
  10.  
  11. void filestat1(void);
  12. void filestat2(void);
  13. void filetime1(void);
  14. void filetime2(void);
  15. void sizecmp(void);
  16. void blockcmp(void);
  17. void datecmp(void);
  18. void timecmp(void);
  19.  
  20. int main(void)
  21. {
  22. filestat1();
  23. filestat2();
  24. filetime1();
  25. filetime2();
  26. sizecmp();
  27. blockcmp();
  28. datecmp();
  29. timecmp();
  30. }
  31.  
  32. void filestat1(void)
  33. {
  34. // check if there is no text1
  35. int check = 0;
  36. check = stat("text1", &stat1);
  37.  
  38. if(check != 0)
  39. {
  40. printf("Error : there is no text1n");
  41. }
  42. return;
  43. }
  44.  
  45. void filestat2(void)
  46. {
  47. // check if there is no text2
  48. int check = 0;
  49. check = stat("text2", &stat2);
  50.  
  51. if(check != 0)
  52. {
  53. printf("Error : there is no text2n");
  54. }
  55. return;
  56. }
  57.  
  58. void filetime1(void)
  59. {
  60. time1 = localtime(&stat1.st_mtime);
  61. return;
  62. }
  63.  
  64. void filetime2(void)
  65. {
  66. time2 = localtime(&stat2.st_mtime);
  67. return;
  68. }
  69.  
  70.  
  71. void sizecmp(void)
  72. {
  73. printf("size comparen");
  74. //variable declare
  75. long long int text1_size;
  76. long long int text2_size;
  77.  
  78. //variable initialize
  79. text1_size = stat1.st_size;
  80. text2_size = stat2.st_size;
  81. if(text1_size > text2_size)
  82. printf("text1 is biggern");
  83. else if(text1_size < text2_size)
  84. printf("text2 is biggern");
  85. else
  86. printf("same sizen");
  87.  
  88. printf("n");
  89. return;
  90. }
  91.  
  92. void blockcmp(void)
  93. {
  94. printf("block comparen");
  95. //variable declare
  96. long long int text1_block_size;
  97. long long int text2_block_size;
  98. //variable initialize
  99. text1_block_size = stat1.st_blocks;
  100. text2_block_size = stat2.st_blocks;
  101.  
  102. if(text1_block_size > text2_block_size)
  103. printf("text1 is biggern");
  104. else if(text1_block_size < text2_block_size)
  105. printf("text2 is biggern");
  106. else
  107. printf("same sizen");
  108.  
  109. printf("n");
  110. return;
  111. }
  112.  
  113. void datecmp(void)
  114. {
  115. printf("date comparen");
  116. // compare tm_mon
  117. if(time1->tm_mon > time2->tm_mon)
  118. printf("time1 is early n");
  119. else if(time1->tm_mon < time2->tm_mon)
  120. printf("time2 is early n");
  121. else{
  122. // compare tm_mday
  123. if(time1->tm_mday > time2->tm_mday)
  124. printf("time1 is early n");
  125. else if(time1->tm_mday < time2->tm_mday)
  126. printf("time2 is early n");
  127. // same date
  128. else
  129. printf("same time n");
  130. }
  131. printf("n");
  132. }
  133.  
  134. void timecmp(void)
  135. {
  136. printf("time comparen");
  137. // compare hour
  138. if(time1->tm_hour > time2->tm_hour)
  139. printf("time1 is early n");
  140. else if(time1->tm_hour < time2->tm_hour)
  141. printf("time2 is early n");
  142. else{
  143. // compare minutes
  144. if(time1->tm_min > time2->tm_min)
  145. printf("time1 is early n");
  146. else if(time1->tm_min < time2->tm_min)
  147. printf("time2 is early n");
  148. // same time
  149. ;else
  150. printf("same time n")
  151. }
  152. }
Add Comment
Please, Sign In to add comment