SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 08/12/2009, 01:09 AM   #1
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Having trouble with fwrite

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 Code:
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:
Code:
[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?
tom_jonez is offline  
Old 08/12/2009, 06:43 PM   #2
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: Having trouble with fwrite

Can I get some help on some file experts?
tom_jonez is offline  
Old 09/12/2009, 08:33 PM   #3
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: Having trouble with fwrite

Please please pleaseee. Crucial functioN!
tom_jonez is offline  
Old 10/12/2009, 12:04 AM   #4
Backwardsman97
High-roller
 
Backwardsman97's Avatar
 
Join Date: Nov 2007
Posts: 1,501
Reputation: 36
Default Re: Having trouble with fwrite

I'll work on it right now and see if I can fix it for yah.
Backwardsman97 is offline  
Old 10/12/2009, 12:06 AM   #5
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: Having trouble with fwrite

Thank you so much backwards.
tom_jonez is offline  
Old 10/12/2009, 12:06 AM   #6
Backwardsman97
High-roller
 
Backwardsman97's Avatar
 
Join Date: Nov 2007
Posts: 1,501
Reputation: 36
Default Re: Having trouble with fwrite

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.
Backwardsman97 is offline  
Old 10/12/2009, 12:07 AM   #7
Mikep.
Huge Clucker
 
Join Date: Sep 2009
Posts: 465
Reputation: 0
Default Re: Having trouble with fwrite

Some indentation so people could read it properly would be nice.
Mikep. is offline  
Old 10/12/2009, 12:08 AM   #8
Backwardsman97
High-roller
 
Backwardsman97's Avatar
 
Join Date: Nov 2007
Posts: 1,501
Reputation: 36
Default Re: Having trouble with fwrite

Forget my last post. It's a very small function that is indented, just the brackets need to be moved down.
Backwardsman97 is offline  
Old 10/12/2009, 12:09 AM   #9
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: Having trouble with fwrite

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
tom_jonez is offline  
Old 10/12/2009, 10:32 PM   #10
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: Having trouble with fwrite

*help call*
tom_jonez is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fwrite help!! Jokerstyle Help Archive 1 27/05/2010 04:21 PM
Fwrite problem billy4601 Help Archive 4 26/03/2010 07:37 PM
fwrite issue Paladin Help Archive 3 12/09/2009 08:09 AM
fwrite thuron Help Archive 9 09/08/2009 06:19 PM


All times are GMT. The time now is 11:55 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.