Opening a file for write problem
Posted on 2002-03-28
I'd be grateful if anybody could help me with this problem as it's driving me mad!
Basically I have a flat text file called days.txt, in it are 7 lines, each corresponding to a day of the week seperated with the | symbol and a number:
I want to open the file, modify one of the numbers (dependant on some processing) then write the file away again.
If I OPEN the file for WRITE, assign the contents to an array, then modify one line element then PRINT and CLOSE the file, I end up with a blank file other than one element (all existing contents are removed).
If I OPEN the file for APPEND, do the same, I get the amended line at the end of a blank file (regardless of what element I tell it to update).
And finally (obviously) if I OPEN the file READ ONLY, I can't write to it any way.
How do I open the file, read contents into the array, modify one array element, then write the file back keeping all the original data except the changed element?
Any help would be appreciated, although I probably won't check here until after Easter (Tuesday 02/04/02).