SA-MP Forums Archive
Having trouble with fwrite - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Having trouble with fwrite (/showthread.php?tid=112473)



Having trouble with fwrite - tom_jonez - 08.12.2009

Gotta say, I hate working with files, but sometimes u have to

Anyways, heres the scenario. I am trying to make a simple setVarInFile function to rewrite a variable, just like dudb but a little different. Heres the code for it:
pawn Код:
setVarInFile(file[],variable[],value[]) {
    new string[512],File:vfile = fopen(file,io_readwrite);
    format(variable,strlen(variable)+1,"%s:",variable);
    format(value,strlen(value)+2,"%s\r\n",value);
    while(fread(vfile,string)) {
      if(!strcmp(variable,string,false,strlen(variable))) {
        strdel(string,strlen(variable)+2,strlen(string)-2);
        strins(string,value,strlen(variable)+2);
        printf("String:%s",string);
        fwrite(vfile,string);
            fclose(vfile);
            printf("Variable %s now returns the value: %s\r\nIt should return %s.\r\nFile:%s",variable,getVarFromFile(file,variable),value,file);
        return 1;
        }
    }
    fclose(vfile);
    return 0;
}
But it doesn't rewrite the variable.
The debug prints return the following:
Код:
[20:55:21] String:AdminReplies: 1
                                       //space is there due to \r\n
[20:55:21] Variable AdminReplies returns the value: 0
[20:55:21] Variable AdminReplies now returns the value: 0
It should return 1.
File:Tickets/R4nk3d-Testing testing testing_12-7-2009.txt
[20:55:24] Variable AdminReplies returns the value: 0 //This one prints because of the getVarFromFile function, which works 100% how it should
Can anyone pick anything out of here as to why it's not writing the new values?


Re: Having trouble with fwrite - tom_jonez - 08.12.2009

Can I get some help on some file experts?


Re: Having trouble with fwrite - tom_jonez - 09.12.2009

Please please pleaseee. Crucial functioN!


Re: Having trouble with fwrite - Backwardsman97 - 10.12.2009

I'll work on it right now and see if I can fix it for yah.


Re: Having trouble with fwrite - tom_jonez - 10.12.2009

Thank you so much backwards.


Re: Having trouble with fwrite - Backwardsman97 - 10.12.2009

Lol, np. Just show me the format of the data in the file you're attempting to change and what you're plugging into this function.


Re: Having trouble with fwrite - Mikep. - 10.12.2009

Some indentation so people could read it properly would be nice.


Re: Having trouble with fwrite - Backwardsman97 - 10.12.2009

Forget my last post. It's a very small function that is indented, just the brackets need to be moved down.


Re: Having trouble with fwrite - tom_jonez - 10.12.2009

Quote:
Originally Posted by Mikep.
Some indentation so people could read it properly would be nice.
are u effing kidding me? except for 3 lines, everything is indented perfectly...


and backwards, ill pm u it

EDIT: nvm i wont pm. if you need anymore code, tell me


Re: Having trouble with fwrite - tom_jonez - 10.12.2009

*help call*