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
#2

Can I get some help on some file experts?
Reply
#3

Please please pleaseee. Crucial functioN!
Reply
#4

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

Thank you so much backwards.
Reply
#6

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.
Reply
#7

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

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

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
Reply
#10

*help call*
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)