AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Remove a line from a file? (https://forums.alliedmods.net/showthread.php?t=156228)

Desikac 05-02-2011 18:47

Remove a line from a file?
 
I want to remove a line from a file which contains a specific string. I did it by doing an empty write_file on that line but that leaves a blank row in a file. How can I delete the line without leaving a blank row?

Exolent[jNr] 05-02-2011 19:14

Re: Remove a line from a file?
 
Read the whole file contents, then write all of the contents into a new file without that 1 line.
Then delete the old file and rename the new file to the old one.

Desikac 05-04-2011 17:01

Re: Remove a line from a file?
 
Is there another option?

Because the file can have over 2000 lines (steam ids) and it deletes a line 5-6 times per map. The file is accessed over 300 times per map.

SonicSonedit 05-04-2011 17:10

Re: Remove a line from a file?
 
Desikac
Bufferize the file in an array on plugin_cfg and work with array directly, save it to file on plugin_end. But this will use up as much memory as file size is. You can also try using ftell/fseek (check file.inc).

ConnorMcLeod 05-04-2011 17:13

Re: Remove a line from a file?
 
Use write_file and specify the line number, the wanted line won't really be removed but it will be blank.

SonicSonedit 05-04-2011 17:17

Re: Remove a line from a file?
 
ConnorMcLeod
I know it's offtopic, but can you tell me, array in pawn use only cellsize*arraysize bytes for memory allocation, or (cellsize+2)*arraysize or (cellsize+4)*arraysize ?

ConnorMcLeod 05-04-2011 17:45

Re: Remove a line from a file?
 
I have no idea of what you are talking about ;)

SonicSonedit 05-04-2011 19:22

Re: Remove a line from a file?
 
ConnorMcLeod
I mean, is pawn using just a dinamic array, one-way vector (with data* next) or two-way vector (with data* next, prev) ?

By saying "one-way vector" I mean something like this (sorry for my poor knowledge or english computer terms):
PHP Code:

struct TVectorData
{
    
TVectorDatanext;
    
voiddata;
};

class 
TVector
{
    
int Size;
    
struct TVectorDataVectorData;
}; 

(rough example, but you get the idea).

fysiks 05-04-2011 19:23

Re: Remove a line from a file?
 
Quote:

Originally Posted by SonicSonedit (Post 1463379)
ConnorMcLeod
I mean, is pawn using an array, one-way (with data* next) vector or two-way (with data* next, prev) vector?

Have you consulted the PAWN manual?

SonicSonedit 05-04-2011 19:43

Re: Remove a line from a file?
 
Quote:

_first (arrayid, index, &success = 0);
_next (arrayid, index, &success = 0);
_prev (arrayid, index, &success = 0);
_last (arrayid, index, &success = 0);
Ok, got it.


All times are GMT -4. The time now is 04:25.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.