Need some help with fdeleteline
#1

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.
Reply
#2

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)