Delete custom name from files
#3

deleting a line is quite an annoying process but basically you just read the file and write everything expect the line in another file, afterwards you just put the whole data from the temp file in the original one

pawn Код:
new
    File: oFile,
    filename[32];
format(filename, sizeof filename, "tmp%s.ini", GetOrgName(PlayerOrg[playerid]));
if((oFile = fopen(filename[3], io_read))) { // open the original file
    new
        File: tFile;
    if((tFile = fopen(filename, io_write))) { // opens the temp file, "tmpORIGINAL.ini"
        new
            tmp[MAX_PLAYER_NAME + 2],
            name[sizeof tmp];
        strcat(name, oPlayerName(playerid)); // save the name into a variable
        strcat(name, "\r\n"); // needed to prevent to call StripNewLine
        while(fread(oFile, tmp)) {
            if(strcmp(tmp, name, false) == 0) { // we found the line
                while(fread(oFile, tmp)) { // skips the check, since we already found it
                    fwrite(tFile, tmp);
                }
                break;
            }
            fwrite(tFile, tmp);
        }
        fclose(oFile);
        fclose(tFile);
        tFile = fopen(filename, io_read);
        oFile = fopen(filename[3], io_write);
        while(fread(tFile, tmp)) { // put the data back into the original
            fwrite(oFile, tmp);
        }
        fclose(tFile);
        fremove(filename); // removes the temp file
    }
    fclose(oFile);
}
Reply


Messages In This Thread
Delete custom name from files - by Zcelo12 - 14.01.2012, 12:42
AW: Delete custom name from files - by Zcelo12 - 14.01.2012, 13:39
AW: Delete custom name from files - by Nero_3D - 14.01.2012, 14:02
AW: Delete custom name from files - by Zcelo12 - 16.01.2012, 10:56
AW: Delete custom name from files - by Nero_3D - 20.01.2012, 12:27

Forum Jump:


Users browsing this thread: 1 Guest(s)