Guest User

Untitled

a guest
May 23rd, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <windows.h>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. void ReadTimeValues(vector<long>& vec)
  8. {
  9.    
  10.     FILE* f = fopen("time.txt", "r");
  11.     if(f)
  12.     {
  13.         long date;
  14.         while(feof(f))
  15.         {
  16.             fscanf (f, "%d\n", &date);
  17.             vec.push_back(date);
  18.         }                      
  19.         fclose(f);
  20.     }
  21. }
  22.  
  23. void SaveDate(long date)
  24. {
  25.     FILE* f = fopen("time.txt", "a+");
  26.     fprintf(f, "%d", date);
  27.     fclose(f);
  28. }
  29.  
  30. int main()
  31. {
  32.     SYSTEMTIME lt;
  33.     GetLocalTime(&lt);
  34.  
  35.     long currentDate = lt.wYear * 10000 + lt.wMonth*100 + lt.wDay;
  36.     vector<long> timeVector;
  37.     ReadTimeValues(timeVector);
  38.  
  39.     bool dateFound = false;
  40.     for(size_t i = 0; i < timeVector.size(); ++i)
  41.     {
  42.         if ( currentDate == timeVector[i] )
  43.             dateFound = true;
  44.     }
  45.  
  46.     if(!dateFound)
  47.     {
  48.         //aici faci apelurile catre functia system(...)
  49.         //in loc de .bat file
  50.         SaveDate(currentDate);
  51.     }
  52.      
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment