hello, I would require to Indentify and Remove a line from a txt file, any ideas?
#6

You can only use dini/dudb/etc if you actually have the file saved in their format

Anyways create a new file without the line you wanted and the rewrite the old file with the created one. Then delete the created one.
pawn Код:
new aLineFromTheFile[256];
new File:f = fopen("file.txt", io_read);
new File:temp = fopen("temp.txt", io_write);

while (fread(f, aLineFromTheFile))
{
    if (strcmp (aLineFromTheFile, "The line I want") == 0)
    {
        printf("This line won't get written in the temp file");
        continue;
    }
    fwrite(temp, aLineFromTheFile);
}
fclose(f);
fclose(temp);

//rewriting the original file with the temp one
f = fopen("file.txt", io_write);
temp = fopen("temp.txt", io_read);
while (fread(temp, aLineFromTheFile))
{
    fwrite(f, aLineFromTheFile);
}
Fremove("temp.txt");
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)