string compare and fstream

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2005
Posts: 13
Reputation: cap2361 is an unknown quantity at this point 
Solved Threads: 0
cap2361 cap2361 is offline Offline
Newbie Poster

string compare and fstream

 
0
  #1
Mar 27th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 19
Reputation: Pikachu is an unknown quantity at this point 
Solved Threads: 0
Pikachu's Avatar
Pikachu Pikachu is offline Offline
Newbie Poster

Re: string compare and fstream

 
0
  #2
Apr 27th, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC