14.01.2012, 14:02
(
Последний раз редактировалось Nero_3D; 20.01.2012 в 12:29.
)
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);
}