Delete 1 line in file - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Delete 1 line in file (
/showthread.php?tid=72335)
Delete 1 line in file -
Jefff - 07.04.2009
Hi I've a big problem i can't create this function :/ fdeleteline by Sacky doesn't work so not give me this
maybe u have your own function?
Re: Delete 1 line in file -
Nubotron - 07.04.2009
How you want delete line? By line number, or what else?
Re: Delete 1 line in file -
Jefff - 07.04.2009
yes or text, I've this in file for example
Code:
sd
afd
hgfgh
gfjg
34v3g
4g234
jgdfg
ghj
and I want delete one of this
Re: Delete 1 line in file -
Nubotron - 07.04.2009
To remove a line by line number, you can use something like this (no it isn't Sacky's function, i have just writted it now! and work):
pawn Code:
fdeleteline(filename[], line)
{
new count, string[256], File:file, File:temp;
file= fopen(filename, io_read);
temp = fopen("tmpfile.tmp", io_write);
while (fread(file, string))
if (++count != line)
fwrite(temp, string);
fclose(file);
fclose(temp);
file= fopen(filename, io_write);
temp = fopen("tmpfile.tmp", io_read);
while (fread(temp, string))
fwrite(file, string);
fclose(file);
fclose(temp);
fremove("tmpfile.tmp");
}
If your file is file.txt, and it contain this:
if you do
pawn Code:
fdeleteline("file.txt", 3);
then file.txt will now contain
Re: Delete 1 line in file -
ICECOLDKILLAK8 - 07.04.2009
Or read the entire file to a buffer, Use strreplace, Then write it back to the file
Re: Delete 1 line in file -
Jefff - 07.04.2009
I have this
Code:
stock fdeleteline(filename[], dest[], remove[])
{
new string[255], File:handle, File:ftmp;
handle = fopen(filename, io_read);
ftmp = fopen(dest, io_write);
while(fread(handle, string)){
for(new i = 0, j = strlen(string); i < j; i++) if(string[i] == '\n' || string[i] == '\r') string[i] = '\0';
if(strcmp(string, remove, false) != 0) fwrite(ftmp, string);
}
fclose(handle);
fclose(ftmp);
handle = fopen(filename, io_write);
ftmp = fopen(dest, io_read);
while(fread(ftmp, string)){
for(new i = 0, j = strlen(string); i < j; i++) if(string[i] == '\n' || string[i] == '\r') string[i] = '\0';
fwrite(handle, string);
}
fclose(handle);
fclose(ftmp);
fremove(dest);
}
but this write
Code:
sdf sffsfa dgsd dhfh dghfh
without spaces and I want that
Code:
sdf
sffsfa
dgsd
dhgfh
Re: Delete 1 line in file -
Nubotron - 08.04.2009
You remove newline characters so..