Delete custom name from files
#1

Hey guy's,
I've a file with a few names:
Код:
Zcelo12
ProGamer
HardCore
And with a command i ant to remove the name "HardCore".
But i don't know how to make that. I tried taht one:

Код:
CMD:removebl(playerid,params[])
{
if (PlayerOrg[playerid] == 0) return SendError(playerid," You aren't in any faction!");
if(IsLeader(playerid) || IsPlayerRank(playerid) > 2)
{
new id;
if(sscanf(params,"u",id)) return SendUsage(playerid," /removebl [playerid]");
if(!IsPlayerConnected(id) || IsPlayerNPC(id)) return SendError(playerid," Player is not connected!");
if(Org_Blacklist(id,GetOrgID(oPlayerName(id))))
{
new name[64];
format(name,sizeof(name),"%s.ini",GetOrgName(PlayerOrg[playerid]));
new File: file = fopen(name, io_read);
if(file)
{
new valtmp[MAX_PLAYER_NAME];
while (fread(file, valtmp))
{
StripNewLine(valtmp);
if (!strcmp(valtmp, oPlayerName(playerid), true, strlen(oPlayerName(playerid))))
{
strdel(valtmp,0,24);
fclose(file);
return 1;
}
}
}
}
}
return 1;
}
I hope anyone can help me.
Greetings
Reply
#2

I tried fdeleteline, but this function removes everything from the file?!
Reply
#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
#4

Big Thanks to you
But 'filename' does not remove with fremove();
Reply
#5

Quote:
Originally Posted by Zcelo12
Посмотреть сообщение
Big Thanks to you
But 'filename' does not remove with fremove();
Ah, sure because it is still opend while the code executes fremove (I edited my last post)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)