Thread: A counter variable problem.

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    3

    A counter variable problem.

    Hello!
    I am working on a program and i have a little problem.
    I have a counter variable in the program, the problem is that every time i close the program and run it again, the counter variable is set back to zero, which is not what i want, i want the counter to hold the value from the last session, please help if you can!

  2. #2
    spaghetticode
    Guest
    Then you need to store it on a physical drive and read it back in when your program starts. "Persistence" is the term you're looking for.

    EDIT: Depending on your progress in C programming, the tutorial on this very website might make do: http://www.cprogramming.com/tutorial/cfileio.html
    Last edited by spaghetticode; 10-01-2015 at 06:12 AM.

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    3
    Thanks for responding!
    The tutorial you gave me explains how to write into a file, so I should store the lase value in a file and read it back when the user opens the program again.
    Is there a way i can store it in memory directly?

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Christo95 View Post
    Is there a way i can store it in memory directly?
    There are ways to do this, but restarting the computer would wipe out the value. The file you write is likely to get cached in memory anyway, if you're accessing it often enough, so it may be a moot point.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    Registered User
    Join Date
    Oct 2015
    Posts
    3
    The file is going to be accessed everytime the user opens the program, so i guess this might be the best solution, thanks for help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help using counter variable with OpenMP
    By DaveDexter in forum C Programming
    Replies: 5
    Last Post: 10-15-2014, 04:05 PM
  2. counter problem
    By sme7000 in forum C Programming
    Replies: 1
    Last Post: 12-14-2009, 02:28 AM
  3. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 03:17 AM
  4. Counter Problem
    By MethodMan in forum C Programming
    Replies: 8
    Last Post: 02-29-2004, 02:24 PM
  5. counter problem
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 03-09-2002, 06:07 PM