Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #define SUBOR "date.txt"
- #define TURN_ON 0
- #define TURN_OFF 1
- int main(){
- time_t t = time(NULL);
- struct tm tm = *localtime(&t);
- int actDate, actTime, fileDate, fileTime, times;
- FILE *f;
- actDate = tm.tm_mday;
- actTime = (tm.tm_hour*100) + (tm.tm_min);
- f = fopen(SUBOR, "r");
- fscanf(f, "%d, %d, %d", &fileDate, &fileTime, ×);
- fclose(f);
- if(fileDate==actDate) {
- if(times++>3 || actTime<(fileTime+200)){
- return TURN_OFF;
- }
- }
- else{
- times=0;
- }
- f = fopen(SUBOR, "w");
- fprintf(f, "%d %d %d", actDate, actTime, times);
- fclose(f);
- return TURN_ON;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement