Raised This Month: $ Target: $400
 0% 

Writing into a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bladell
Senior Member
Join Date: Jun 2012
Old 06-18-2014 , 03:22   Re: Writing into a file
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <regsysnat>

#define NAME    "Weekly question"
#define VERSION    "1.0"
#define AUTHOR    "Marius"

new file1[64];

public 
plugin_init()
{
    
register_plugin(NAMEVERSIONAUTHOR);
    
    
exec_files();
}

public 
exec_files()
{
    
get_configsdir(file163);
    
    
add(file1sizeof(file1) - 1"/qofw/questions.ini");
    
    if(!
file_exists(file1))
    {
        
log_to_file("Questions.log""%s nu exista"file1);
        return 
PLUGIN_HANDLED
    
}
    
    
    return 
1
}


public 
rs_logged_in(id)
{    
    new 
name[64], text[64], 0;
    
get_user_name(idnamecharsmax(name));
    new 
fHandle fopen(file1"wt")
    
    
formatex(textcharsmax(text), "%s fputs"name)
    
fputs(fHandletext)
    
write_file (file1"write_file"3)
    
fprintf(fHandle"%s frpint"name);
    
    
fclose(fHandle)

All of this three methods are working with this test plugin... wich of them should I use and what should I modify to my plugin?

" I'm surprised you are not getting run-time errors for this."
I'm getting run-time errors

Code:
L 06/18/2014 - 09:22:00: [AMXX] Displaying debug trace (plugin "qofweek.amxx")
L 06/18/2014 - 09:22:00: [AMXX] Run time error 11: divide 
L 06/18/2014 - 09:22:00: [AMXX]    [0] qofweek.sma::write_info (line 141)
L 06/18/2014 - 09:22:00: [AMXX]    [1] qofweek.sma::menu_handler (line 266)
I suppose that this errors appear because this plugin have nothing to read from file.
Bladell is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-18-2014 , 06:40   Re: Writing into a file
Reply With Quote #2

Never use write_file() or read_file(), period, especially when already using the fopen() method. Always use the fopen(), fclose(), etc. method.

Also, that error has nothing to do with what I was referring to.
__________________

Last edited by fysiks; 06-18-2014 at 06:41.
fysiks 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 21:10.


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