AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   reading & writing to a file (https://forums.alliedmods.net/showthread.php?t=25230)

p3tsin 03-10-2006 12:52

reading & writing to a file
 
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 :)

p3tsin 03-11-2006 13:31

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? :?

PM 03-11-2006 13:59

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.

p3tsin 03-11-2006 15:02

*-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


All times are GMT -4. The time now is 20:18.

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