Need some help with fdeleteline - 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: Need some help with fdeleteline (
/showthread.php?tid=96808)
Need some help with fdeleteline -
Gappy - 11.09.2009
pawn Код:
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);
}
I need someone to help modify that code so instead of rewriting the file like this:
Код:
test1test2test3test4test5....
It writes it like this:
Код:
test1
test2
test3
test4
....
Cheers.
Re: Need some help with fdeleteline -
Gappy - 11.09.2009
I've tried this aswell but it doesn't work.
pawn Код:
public fdeleteline(filename[], line[]){
if(fexist(filename)){
new temp[256];
new File:fhandle = fopen(filename,io_read);
fread(fhandle,temp,sizeof(temp),false);
if(strfind(temp,line,true)==-1){return 0;}
else{
fclose(fhandle);
fremove(filename);
for(new i=0;i<strlen(temp);i++){
new templine[256];
strmid(templine,temp,i,i+strlen(line));
if(strcmp(templine, line, true) == 0){
strdel(temp,i,i+strlen(line));
fcreate(filename);
fhandle = fopen(filename,io_write);
fwrite(fhandle,temp);
fclose(fhandle);
return 1;
}
}
}
}
return 0;
}