PDA

View Full Version : changing array value in external file


loonatik
04-24-2003, 10:56 PM
I have to write a program that opens an external .dat file and change one of its values without erasing all the contents. The file has floatint point numbers and characters. Like:

=============
123.56 doe, john
789.01 moe, joe
...and so on
=============

The program

1. asks the user for his name which are stored as two strings
2. asks the user for a number to be added
3. opens file and searches for the name
4. when it finds the match, the number to be added is added to the number next to the name

Example run:
1. what is your name? doe, john
2. how much to add? 4
3. done

and the file would read:
=============
127.56 doe, john
789.01 moe, joe
...and so on
=============

What I did was change the value and write it back to the file, but it erases everything in the file. There's gotta be a smart solution...?
Thanks!!

smeagol
04-25-2003, 03:44 AM
What language are you using to write this program?

loonatik
04-25-2003, 04:19 AM
C++

Jason
04-26-2003, 12:15 AM
some how, I don't think you can do this...maybe you can copy all the data out and then delete the file and then export all the data values that have changed into a file with the exact same name. But Im not to sure if you can just delete segments of the file, I don't think there is anything in C++ that allows that. But then again, deleting the file, not to sure how to do that either....


Jason