Advertisement
hocikto19

Improved date check

Mar 6th, 2015
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. #define SUBOR "date.txt"
  5. #define TURN_ON 0
  6. #define TURN_OFF 1
  7.  
  8. int main(){
  9.         time_t t = time(NULL);
  10.         struct tm tm = *localtime(&t);
  11.         int actDate, actTime, fileDate, fileTime, times;
  12.         FILE *f;
  13.         actDate = tm.tm_mday;
  14.         actTime = (tm.tm_hour*100) + (tm.tm_min);
  15.    
  16.         f = fopen(SUBOR, "r");
  17.         fscanf(f, "%d, %d, %d", &fileDate, &fileTime, &times);
  18.         fclose(f);
  19.    
  20.         if(fileDate==actDate) {
  21.            if(times++>3 || actTime<(fileTime+200)){
  22.               return TURN_OFF;
  23.            }
  24.         }
  25.         else{
  26.            times=0;
  27.         }
  28.    
  29.         f = fopen(SUBOR, "w");
  30.         fprintf(f, "%d %d %d", actDate, actTime, times);
  31.         fclose(f);
  32.         return TURN_ON;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement