Exchange two file by time


/ Published in: C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. void writer(FILE *fout, FILE *fin);
  6. int main (void) {
  7. FILE *shab, *rooz, *vnstat;
  8.  
  9. char shabane[] = ".shabane";
  10. shab = fopen(shabane, "r");
  11.  
  12. char roozane[] = ".roozane";
  13. rooz = fopen(roozane, "r");
  14.  
  15. char vnstatrc[] = ".vnstatrc";
  16. vnstat = fopen(vnstatrc, "w");
  17.  
  18. time_t now_time;
  19. time (&now_time);
  20.  
  21. struct tm *now;
  22. now = localtime(&now_time);
  23.  
  24. int hour;
  25. hour = now->tm_hour;
  26.  
  27. if ( hour >= 3 & hour <= 7 ) {
  28. writer(vnstat, shab);
  29. } else {
  30. write(vnstat, rooz);
  31. }
  32.  
  33.  
  34. fclose(vnstat);
  35. fclose(shab);
  36. fclose(rooz);
  37.  
  38. return 0;
  39. }
  40.  
  41. void writer(FILE *fout, FILE *fin) {
  42. int c;
  43. while((c = fgetc(fin)) != EOF) {
  44. fputc(c, fout);
  45. }
  46. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.