Deleting lines in a file
Author |
Message |
n_n
|
Posted: Tue Oct 11, 2005 9:29 am Post subject: Deleting lines in a file |
|
|
I've tried looking at all the current tutorials and can't really find it. I'm making a phonebook program that can add, delete, edit, and display numbers stored in a file. So far, I've completed everything except for deleting and editing. Once I get deleting I can do editting though. Anyways, I can't get my deleting portion working. I've tried one way but it seems extremely unefficient (and doens't work) and wondering if someone can direct me in the right direction.
Well, what I do is when I read a file, I assign each line of the file an ID. When I want to delete, I find out that ID and read the file up to and including that line counting the length of every word/number inputted (we'll call this eraseCount). I then count the length of the one I want to delete (eraseThis). Now, all I do is read the file and locate to eraseCount which (I think) leads me to the end of the line I want to delete. Now I just put in a repeated backspace via ASCII with eraseThis as a counter.
Now, this doesn't work and sounds stupid in my mind. Can anyone suggest a better way? Thanks in advanced. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Tue Oct 11, 2005 9:48 am Post subject: (No subject) |
|
|
a better way would be to use records and random-access (aka read/write) |
|
|
|
|
![](images/spacer.gif) |
n_n
|
Posted: Wed Oct 12, 2005 8:51 am Post subject: (No subject) |
|
|
Well, I do have records. I'm still kinda confused about where you're trying to direct me. Maybe I can rewrite the file? I'm not sure. |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Wed Oct 12, 2005 2:47 pm Post subject: (No subject) |
|
|
The way file i/o in Turing works is that you will in almost all situations have to copy the file to a variable, then rewrite that file with the new value of that variable (array/record/string/etc) which was changed by the program. |
|
|
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: Thu Oct 13, 2005 1:18 am Post subject: (No subject) |
|
|
it store in .txt???
So you could change it directly?? and say, CHEAT in a RPG?? |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Thu Oct 13, 2005 2:45 pm Post subject: (No subject) |
|
|
Sigh... he is talking about a phone book, not an RPG. Not everyone has such ambitions.
If you really want to keep your information secret, then make some type of encryption. In Turing, it shouldn't really matter because noone will care enough . |
|
|
|
|
![](images/spacer.gif) |
|
|