Raised This Month: $ Target: $400
 0% 

reading & writing to a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 03-10-2006 , 12:52   reading & writing to a file
Reply With Quote #1

EDIT: just figured that out, so im gonna replace this with another question:

if i wanted to first read a file and then write into it, what should i put as mode[].. tried "wrt" but i couldnt read from it

EDIT2: of yeah, and im talking about the new file natives
__________________
plop
p3tsin is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 03-11-2006 , 13:31  
Reply With Quote #2

oh come on!

i made a test script; it reads the file just fine but cant write anything into it
Code:
new form[128], steamid[32] get_user_authid(id, steamid,31) format(form,127, "%s %s", steamid, bla) new data[64], authid[32], len new fid = fopen(settingsfile, "rwt") while(!feof(fid)) {     fgets(fid, data,63)     len = strlen(data) * -1     strbreak(data, authid,31, data,1)     if(!equal(steamid,authid)) continue     fseek(fid, len,SEEK_CUR)    //goto start of the line     break } fprintf(fid, form) fclose(fid)

or do i just need to first read, then close and open it again for writing?
__________________
plop
p3tsin is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 03-11-2006 , 13:59  
Reply With Quote #3

I guess you want r+t . Click here for more info.

On a side note, fprintf does formatting, so my best bet is this:

Code:
new steamid[35] // EKS says so: <a href="http://forums.alliedmods.net/showthread.php?t=3420" target="_blank" rel="nofollow noopener">http://forums.alliedmods.net/showthread.php?t=3420</a> get_user_authid(id, steamid,34) new data[64], authid[32], len new fid = fopen(settingsfile, "r+t") while(!feof(fid)) {     fgets(fid, data,63)     len = strlen(data) * -1  // why *-1 if I may ask? :o     strbreak(data, authid,31, data,1)     if(!equal(steamid,authid)) continue     fseek(fid, len,SEEK_CUR)    //goto start of the line     break } fprintf(fid, "%s %s", steamid, bla) fclose(fid)

Untested, but you get the idea.
__________________
hello, i am pm
PM is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 03-11-2006 , 15:02  
Reply With Quote #4

*-1 is there coz i need to back up, since the position is set to end of the line after fgets()

and i first did format it in fprintf(), but it produced a tag mismatch

anyways, thanks for the link <3
__________________
plop
p3tsin 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 20:18.


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