#define func:%0(%1) stock %0(%1)
func:RemoveSingleLineFromFile(file[], searchfor[], bool:useuppercase = false)
{
new File:fileFile, File:tempFile,
str1[35], str2[100]
;
format(str1, 35, "Temp/TempFile%s.tmp", file);
tempFile = fopen(str1, io_append);
fileFile = fopen(file, io_read);
while(fread(fileFile, str2)){
if(useuppercase){
if(!strcmp(str2, searchfor, false)){
fwrite(tempFile, str2);
break;
}
}
else{
if(!strcmp(str2, searchfor)){
fwrite(tempFile, str2);
break;
}
}
}
fclose(tempFile);
fclose(fileFile);
tempFile = fopen(str1, io_read);
fileFile = fopen(file, io_write);
fwrite(fileFile, " ");
fclose(fileFile);
fileFile = fopen(file, io_append);
while(fread(tempFile, str2))
fwrite(fileFile, str2);
fclose(fileFile);
fclose(tempFile);
fremove(str1);
return 1;
}
RemoveSingleLineFromFile(filename[], searchfor[], bool:useuppercase = false)
{
new File:file = fopen(filename, io_read),
File:tempfile = fopen("temp.txt", io_append),
string[128];
while(fread(file, string))
{
if(!strcmp(string, searchfor, !(useuppercase)))
{
continue;
}
fwrite(tempfile, string);
}
fclose(tempfile);
fclose(file);
fremove(filename);
tempfile = fopen("temp.txt", io_read);
file = fopen(filename, io_append);
while(fread(tempfile, string))
{
fwrite(file, string);
}
fclose(tempfile);
fclose(file);
fremove("temp.txt");
return 1;
}
|
Why would it not work? You've posted it on the forums in response to a question, so that means you have previously tested it. Given that you posted it that means your tests succeeded, so if the code works for you, why would it not work for anyone else?
Also, you both know you can use "ftemp" instead of "fopen" to get a temporary file right? |

