943,712 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 5551
  • C RSS
Mar 27th, 2005
0

string compare and fstream

Expand Post »
I wrote a blackjack game for class and one stipulation is to have a file(fstream). I did get the file stream to work but not like it should. it keeps track of player name and money amount. what i would like to do is give player option to save game. i am confused on how to go about reusing the data from the file. user enters name and program should see if name is in record. then the user can start with the money amount that was saved previously. i was thinking of using string compare but i do not want to change the variable that i am using. (it didn't work anyway). how can i use string compare and access the saved record with the variable being the same name?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cap2361 is offline Offline
13 posts
since Feb 2005
Apr 27th, 2005
0

Re: string compare and fstream

Quote originally posted by cap2361 ...
how can i use string compare and access the saved record with the variable being the same name?
Use a temporary text file. Say, I call it temp.txt
Open temp.txt and the Original file.
Copy the name and balance from the Original file into two temporary variables (one to hold the name, another to hold the balance).
IF the name and the EntryName(the name the user typed at the begining of the game) is NOT the same, you copy the the temporary variable into temp.txt
IF the name and the EntryName IS the SAME, you change the temporary variable's balance to the new balance. THEN only you copy the temporary variable into temp.txt
Finally, you close BOTH files before you delete the Original text file and rename temp.txt into the Original text file's name.

Hope this helped.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Pikachu is offline Offline
19 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: pow() ??
Next Thread in C Forum Timeline: please help me with this problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC