Removing entry (fwrite)
#1

How to remove entry in fwrite, like with INI - INI_RemoveEntry.
I am using INI because I'm beginner, but wanna try to understand fwrite as more as I can, for other things, not SA:MP.

E.g.

Код:
Test1
Test2
Test3
new File:file = fopen("somefile.txt", io_read);
fremoveentry(file, "Test2");
fclose(file);

Would be:
Код:
Test1
Test3
Thanks anyway!
Reply
#2

There's no easy way to do something like that. Pawn's default file functions can't "insert" or "remove" characters in between. By default each character in the text file is fixed to its position in the file. For example if the T of "Test3" is the 15th character in the file, you can only move it to the 8th place by rewriting the whole file from the 7th place until the end of the file. Otherwise you would keep the gap of 7 other characters in between, because you removed the info there while the next line is still positioned at the 15th spot. Furthermore, if you want to write 10 characters in that gap, it would overwrite some characters of the next line.

I hope it's a clear answer, I don't really know how to describe it otherwise.
Reply
#3

The easiest way is to store every line of your file into buffer, find the line, remove it from buffer, and then skip it while re-writing the file.
Reply
#4

A'ight guys, thank you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)