Saving

This is a discussion on Saving within the Linux Programming forums, part of the Platform Specific Boards category; I've just started scripting and have written a small prog that playes blackjack with the user. What I was wondering, ...

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Saving

    I've just started scripting and have written a small prog that playes blackjack with the user. What I was wondering, how would I make it so the game saved the amount of money the user won and then loaded this amount the next time the game is played?

  2. #2
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Um.. I know how to save in C and C++, but I don't know how to do it in Unix scripting which is what the program is written with.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Here's one way
    Code:
    SCORE=10
    
    echo "SCORE is $SCORE"
    
    echo $SCORE>score.txt
    
    SCORE=0
    
    echo "SCORE is $SCORE"
    
    if [ -f score.txt ]
    then
        SCORE=$(cat score.txt)
    fi
    
    echo "SCORE is $SCORE"
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Thanks! Worked perfectly!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C++ problem saving files
    By wesm in forum C++ Programming
    Replies: 2
    Last Post: 11-02-2005, 01:00 PM
  2. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  3. saving a binary tree??
    By fayte in forum C++ Programming
    Replies: 9
    Last Post: 01-27-2005, 12:32 PM
  4. Saving vectors of structures problem
    By redeck in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2004, 03:47 PM
  5. File saving problem in DevC++ pls help ???
    By intruder in forum C Programming
    Replies: 3
    Last Post: 12-17-2002, 12:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21