07.04.2009, 22:58
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):
If your file is file.txt, and it contain this:
if you do
then file.txt will now contain
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:
Code:
sd afd hgfgh gfjg
pawn Code:
fdeleteline("file.txt", 3);
Code:
sd afd gfjg

