AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   fputs() problem (https://forums.alliedmods.net/showthread.php?t=112702)

grimvh2 12-20-2009 17:12

fputs() problem
 
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.

Arkshine 12-20-2009 17:25

Re: fputs() problem
 
- 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.

matsi 12-20-2009 17:25

Re: fputs() problem
 
Quote:

Originally Posted by grimvh2 (Post 1024443)
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?

grimvh2 12-20-2009 17:56

Re: fputs() problem
 
Quote:

Originally Posted by Arkshine (Post 1024462)
- 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!! :crab:

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

fysiks 12-20-2009 17:58

Re: fputs() problem
 
Quote:

Originally Posted by grimvh2 (Post 1024519)
ah , where did you get fprintf() from?

/addons/amxmodx/scripting/includes/file.inc

Arkshine 12-20-2009 17:59

Re: fputs() problem
 
Oh no, don't say it.

fysiks 12-20-2009 18:00

Re: fputs() problem
 
Quote:

Originally Posted by Arkshine (Post 1024527)
Oh no, don't say it.

huh?

Arkshine 12-20-2009 18:04

Re: fputs() problem
 
Forget, it was just a joke. *sigh*

grimvh2 12-20-2009 18:08

Re: fputs() problem
 
Well for my function references I mostly look at the docs @ www.amxmodx.org/doc

Arkshine 12-20-2009 18:10

Re: fputs() problem
 
You need to look at the .inc files in the includes/ directory.


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

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