Raised This Month: $ Target: $400
 0% 

fputs() problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
grimvh2
Veteran Member
Join Date: Nov 2007
Location: Fishdot Nation
Old 12-20-2009 , 17:12   fputs() problem
Reply With Quote #1

When I use fputs() I can only save 1 line in a .ini or .cfg file.

Im using it like this

Code:
public do_savecmd(id,szNewcmd[],szOldcmd[], szType[])
{
    new iFile = fopen(Path, "w");
    if( !iFile )
        return;
    
    new const szData[100];
    format(szData,sizeof(szData)-1, "^"%s^" ^"%s^" ^"%s^"",szNewcmd,szOldcmd, szType)
    
    fputs(iFile, szData);
    fclose(iFile);
    
    console_print(id, "New Command : %s",szNewcmd)
    console_print(id, "Old Command : %s",szOldcmd)
    console_print(id, "Type : %s", szType)
}
So when I put something in the file, it goes in there. but when I want to put something new in it. It deletes the first line and puts in the new.
__________________
I am out of order!
grimvh2 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-20-2009 , 17:25   Re: fputs() problem
Reply With Quote #2

- First, instead of using format() + fputs() ; you can use directly fprintf().
- If you want to start at the end of file you need to use the "a" flag.
__________________
Arkshine is offline
matsi
Thinkosaur
Join Date: Sep 2006
Old 12-20-2009 , 17:25   Re: fputs() problem
Reply With Quote #3

Quote:
Originally Posted by grimvh2 View Post
When I use fputs() I can only save 1 line in a .ini or .cfg file.

Im using it like this

Code:
public do_savecmd(id,szNewcmd[],szOldcmd[], szType[])
{
    new iFile = fopen(Path, "w");
    if( !iFile )
        return;
    
    new const szData[100];
    format(szData,sizeof(szData)-1, "^"%s^" ^"%s^" ^"%s^"",szNewcmd,szOldcmd, szType)
    
    fputs(iFile, szData);
    fclose(iFile);
    
    console_print(id, "New Command : %s",szNewcmd)
    console_print(id, "Old Command : %s",szOldcmd)
    console_print(id, "Type : %s", szType)
}
So when I put something in the file, it goes in there. but when I want to put something new in it. It deletes the first line and puts in the new.
^n


edit: What about using flags "at"? Would that be correct or incorrect?

Last edited by matsi; 12-20-2009 at 17:29.
matsi is offline
grimvh2
Veteran Member
Join Date: Nov 2007
Location: Fishdot Nation
Old 12-20-2009 , 17:56   Re: fputs() problem
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
- First, instead of using format() + fputs() ; you can use directly fprintf().
- If you want to start at the end of file you need to use the "a" flag.
ah , where did you get fprintf() from?
You know to much!!

Quote:
Originally Posted by matsi
^n
edit: What about using flags "at"? Would that be correct or incorrect?
Seems like i had to use the flag "a" but had to use ^n also but that I would had figuren out. Thanks anyway :p
__________________
I am out of order!
grimvh2 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-20-2009 , 17:58   Re: fputs() problem
Reply With Quote #5

Quote:
Originally Posted by grimvh2 View Post
ah , where did you get fprintf() from?
/addons/amxmodx/scripting/includes/file.inc
__________________
fysiks is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-20-2009 , 17:59   Re: fputs() problem
Reply With Quote #6

Oh no, don't say it.
__________________
Arkshine is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-20-2009 , 18:00   Re: fputs() problem
Reply With Quote #7

Quote:
Originally Posted by Arkshine View Post
Oh no, don't say it.
huh?
__________________
fysiks is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-20-2009 , 18:04   Re: fputs() problem
Reply With Quote #8

Forget, it was just a joke. *sigh*
__________________
Arkshine is offline
grimvh2
Veteran Member
Join Date: Nov 2007
Location: Fishdot Nation
Old 12-20-2009 , 18:08   Re: fputs() problem
Reply With Quote #9

Well for my function references I mostly look at the docs @ www.amxmodx.org/doc
__________________
I am out of order!
grimvh2 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-20-2009 , 18:10   Re: fputs() problem
Reply With Quote #10

You need to look at the .inc files in the includes/ directory.
__________________
Arkshine is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 04:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode