08.12.2009, 01:09
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:
But it doesn't rewrite the variable.
The debug prints return the following:
Can anyone pick anything out of here as to why it's not writing the new values?
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;
}
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