Add line to the top of the file
#1

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);
        }
    }
Reply
#2

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
Reply
#3

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)