| | |
string compare and fstream
![]() |
•
•
Join Date: Feb 2005
Posts: 13
Reputation:
Solved Threads: 0
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?
•
•
•
•
Originally Posted by cap2361
how can i use string compare and access the saved record with the variable being the same name?
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.
![]() |
Similar Threads
- Compare String with Strings (Visual Basic 4 / 5 / 6)
- hi.. string compare (Java)
- assignment help [fstream, on modifying a record in a file] (C++)
- How to see if one string is less than another string (C)
- problem with fstream (C++)
- need info? can't use strcmp/string compare (C++)
- Help with fstream (C++)
Other Threads in the C Forum
- Previous Thread: pow() ??
- Next Thread: please help me with this problem
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o ide inches initialization intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi





