• C

reset a counter every year

I have a counter that I want to
reset the first time anything gets saved
in a new year. But I don't know how
to do it. If anyone can send me some pseudo code or code or an algorithm
or anything I'd be so happy.

I start the counter at zero and the first of january when something gets saved I want it to start at zero again.

thanks!
LVL 3
otroligafreddeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexVirochovskyCommented:
Next way i use :
1. test: exist counter (in ini file or
 for Win95/98 in Registry).
2. If Not exists, save 0 to current
   and set yearSaved to current and
   save in same place.
3. By timer test every hour:
   New year? (compare with saved)
   if new, save new year and counter = 0.
4. Happy New Year!
Alex
0
rgoughCommented:
#define SECONDS_IN_A_YEAR   31556736 /* 60*60*24*365.24 */

/* persistent variables - need to stored to non-volatile memory
 * if your program doesn't run constantly.  
 * good idea even if it is supposed to run constantly
 */
BOOL saved_this_year = FALSE;
time_t this_year = 0;


/* in the code where you do a save */

time_t current_year = time() / SECONDS_IN_A_YEAR;

if (current_year > this_year) {
   saved_this_year = FALSE;
}

if (!saved_this_year) {
   saved_this_year = TRUE;
   this_year = current_year;
   /* reset your counter here */
}
0
inprasCommented:
Can U explain more what difficulty UR facing?
Regards
0
AlexVirochovskyCommented:
otro..., what do you think about
our recomendations?
0
AlexVirochovskyCommented:
otro, sorry, that i reply, but we want
you reaction! what do you think about
our recomendations? It helps or you want something else?
Happy New Year. Alex
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.