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!!
=============
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!!