AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   fseek() (https://forums.alliedmods.net/showthread.php?t=173250)

Diegorkable 12-02-2011 15:03

fseek()
 
Hey guys.

I saw that if you use:

fseek(fp, 0, SEEK_END)

It find you the beginning of the last line in a file.
Does it mean the last EMPTY line? or the last line like this:

if I have a file and it looks like this

Code:

Counter-Strike 1.6 is old
Call of Duty is newer

will it find the beginning of the line "Call of Duty is newer" or the beginning of the last line HERE?:

Code:

Counter-Strike 1.6 is old
Call of Duty is newer
// here??

The reason I want to know is, that I want everytime that something new will be added to a file. So what I want to do is fseek to a NEW LINE, then fputs something. and as far as I know if I use fputs it just erases the first line (or wherever the cursor pointer is found at) and overwrites it with the string parameter you gave.

How can I use fseek to write a new line at the end of the file with fputs? (except of course with using many fgets while !feof, cuz fgets moves the pointer automatically)

Arkshine 12-02-2011 17:17

Re: fseek()
 
To append new contents, just open the file with : fopen and "a" flag.

Diegorkable 12-02-2011 17:54

Re: fseek()
 
then if I use fputs it will just add a new line?

Diegorkable 12-02-2011 18:49

Re: fseek()
 
"a+" Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.

nvm i guess it will.


All times are GMT -4. The time now is 08:26.

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