Raised This Month: $ Target: $400
 0% 

fseek()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 12-02-2011 , 15:03   fseek()
Reply With Quote #1

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)
__________________
My Projects:

Auto-Mix (Pug): 100%

Joined the Military (a soldier now) - Inactive
Diegorkable is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-02-2011 , 17:17   Re: fseek()
Reply With Quote #2

To append new contents, just open the file with : fopen and "a" flag.
__________________
Arkshine is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 12-02-2011 , 17:54   Re: fseek()
Reply With Quote #3

then if I use fputs it will just add a new line?
__________________
My Projects:

Auto-Mix (Pug): 100%

Joined the Military (a soldier now) - Inactive
Diegorkable is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 12-02-2011 , 18:49   Re: fseek()
Reply With Quote #4

"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.
__________________
My Projects:

Auto-Mix (Pug): 100%

Joined the Military (a soldier now) - Inactive

Last edited by Diegorkable; 12-02-2011 at 18:49.
Diegorkable is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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