SA-MP Forums Archive
Add line to the top of the file - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Add line to the top of the file (/showthread.php?tid=564228)



Add line to the top of the file - ahmedkoki - 20.02.2015

Ok so I am using this code but I want it so I can add changes in game but when I add a new update it adds it to the bottom but I want to at it at the top or if there is option to re arrange the dialog items from bottom to top for example like this

If I added a new change like Fixed admin system
Код:
Fixed admin system
Added new commands
Removed some bugs
but instead it writes it like that
Код:
Added new commands
Removed some bugs
Fixed admin system
but I want the last updates I add to appear at the top and here is the pwn code

pawn Код:
if(dialogid == UPDATES_ADD && response)
    {
        new string[128];
        format(string, sizeof(string), "%s\r\n", inputtext);
        new File:tmp=fopen("updates.txt", io_append);
        if(tmp)
        {
            fwrite(tmp, string);
            fclose(tmp);
        }
    }



Re: Add line to the top of the file - Kyance - 20.02.2015

I haven't used the 'file' functions in a while, but, you can try "reading" the updates in a string ( https://sampwiki.blast.hk/wiki/Fread ), and then formatting it like this:
pawn Код:
format(string, sizeof(string), "%s\r\n%s", inputtext, buf);
or w.e


Re: Add line to the top of the file - Vince - 20.02.2015

https://sampwiki.blast.hk/wiki/Fseek
Use seek_start with offset 0 to place the cursor at the start of the file.


Re: Add line to the top of the file - ahmedkoki - 21.02.2015

I don't know how to use fseek, can you give example?


AW: Add line to the top of the file - Nero_3D - 21.02.2015

If you only use fseek you will overwrite the existing data instead
Save the complete file into the memory and add your string at the wanted position (with the str functions)
Write the complete data back to file