Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 11-07-2006, 12:10 AM   #1 (permalink)
True Techie
 
Join Date: Apr 2004
Posts: 115
Send a message via AIM to Toshiro Send a message via Yahoo to Toshiro
Default (C++) Overwriting file after taking input from it?

I'm making a super simple text-based adventure game to test out new things I learn in my introductory C++ class.

I'm trying to implement a simple save feature where the user hits 'R' (for Record) to save to a file called "savefile.txt". I got this working OK so far. It opens (or creates if not existing) the savefile.txt file, then outputs certain variable values to the file in a specific order. It then closes savefile.txt and continues the gameplay part.

When the program starts, the user can hit 'C' (for Continue) to read values from savefile.txt. It reads them into the same variables that were outputted in the save process, and in the same exact order as they were outputted to the file so that everything matches up. The gameplay part continues from here. If savefile.txt does not exist yet or doesn't have acceptable values in it, it will give an error message and terminate.

My problem is... If I choose "continue" and get input values from savefile.txt, I can't get it to overwrite savefile.txt when I save later. It just leaves savefile.txt blank and acts like everything worked fine (I have a "failed to open" error message in place that work fine when something else is wrong).

Also, if savefile.txt already exists and has data in it (from a previous save, for example), I can start a new game and overwrite it perfectly fine, with all correct new values. It just wont let me if I've already taken input from the file during the same run.

Any ideas as to what I might be doing wrong? I can post the code for the "save" and "continue" parts, if that will help.
__________________
Make: eMachines
OS: WinXP Pro
Mobo: Gigabyte 8VM533M-RZ
CPU: 2.2GHz Intel Celeron
Vid: Gigabyte NVidia MX 4000 (128 MB DDR, TV out)
Sound: onboard
RAM: 512MB DDR
HD: 40GB (1:3 partitioned), 34GB
Drives: DVD R/RW and 16x DVD-ROM
Browser: FireFox
ISP: AT&T/SBC Yahoo! DSL
Toshiro is offline   Reply With Quote
Old 11-07-2006, 09:04 AM   #2 (permalink)
Software Developer
 
Join Date: Mar 2006
Location: Columbus, OH
Posts: 468
Default

You should always post the code you are having problems with. It sounds like you may not be closing the file and trying to open it when it's already opened. However, we don't know for sure, so post your code and we'll look at it.
jaeusm is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:23 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0