Having trouble with fwrite
#1

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


Messages In This Thread
Having trouble with fwrite - by tom_jonez - 08.12.2009, 01:09
Re: Having trouble with fwrite - by tom_jonez - 08.12.2009, 18:43
Re: Having trouble with fwrite - by tom_jonez - 09.12.2009, 20:33
Re: Having trouble with fwrite - by Backwardsman97 - 10.12.2009, 00:04
Re: Having trouble with fwrite - by tom_jonez - 10.12.2009, 00:06
Re: Having trouble with fwrite - by Backwardsman97 - 10.12.2009, 00:06
Re: Having trouble with fwrite - by Mikep. - 10.12.2009, 00:07
Re: Having trouble with fwrite - by Backwardsman97 - 10.12.2009, 00:08
Re: Having trouble with fwrite - by tom_jonez - 10.12.2009, 00:09
Re: Having trouble with fwrite - by tom_jonez - 10.12.2009, 22:32

Forum Jump:


Users browsing this thread: 1 Guest(s)