Raised This Month: $ Target: $400
 0% 

Read a line from a file and check


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 11-18-2011 , 14:24   Read a line from a file and check
Reply With Quote #1

Hey guys,

My friend is trying to get a line from a file (you can see how the line should look like in the file from the formatex function he used), I helped him design it a bit cuz it didnt work for him and thats what came out:

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

#define PLUGIN "Prisoner Count"
#define VERSION "1.0"
#define AUTHOR "CreePs"

new PrisonerID[33];
new 
HighestPrisoner;
new 
filename[256]

public 
plugin_init()
{
    
get_configsdirfilename255 )
    
format(filename255"%s/prisoner.ini"filename);
    
register_clcmd("say /test""cmdTest")
}

public 
cmdTest(id)
{
    
client_print(idprint_chat"TESTDSDGFTDGF")
}
    
public 
client_putinserver(id)
{
    
Load(id);
}

Load(id)
{
    new 
data[128];
    new 
Name[64];
    new 
Authid[64];
    new 
ID[64];
    new 
Checkid[64];
    new 
Highest[256];

    
get_user_name(idName63);
    
get_user_authid(idCheckid63);
    
    new 
szReadData[200]
    new 
file fopen(filename"r")

    while( 
fgets(filedatasizeof(data) - 1) )
    {
        
parse(dataNamecharsmax(Name), Authidcharsmax(Authid), IDcharsmax(ID), Highestcharsmax(Highest) );

        if( 
equal(CheckidAuthid) )
        {
            
PrisonerID[id] = str_to_num(ID);    
            
set_user_infoid"name"Name )
            
fclose(file)
            
            return 
PLUGIN_CONTINUE
        
}
        
        
HighestPrisoner str_to_num(Highest);
    }
    
    
PrisonerID[id] = str_to_num(Highest) + 1;
                
    
get_user_authid(idAuthid63);
    
formatex(szReadDatacharsmax(szReadData) - 1"^"%s^" %s  %i %i"NameAuthidPrisonerID[id], PrisonerID[id] > HighestPrisoner PrisonerID[id] : HighestPrisoner);    
    
fputs(fileszReadData)
    
fclose(file)
            
    return 
PLUGIN_CONTINUE

Now he says it doesn't work and writes nothing, in my opinion it should work. Does someone detect something wrong?
__________________
My Projects:

Auto-Mix (Pug): 100%

Joined the Military (a soldier now) - Inactive
Diegorkable is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-18-2011 , 15:53   Re: Read a line from a file and check
Reply With Quote #2

Quote:
Originally Posted by Diegorkable View Post
Now he says it doesn't work and writes nothing, in my opinion it should work.
Wow, you are probably the laziest active member on here.

You can't write to a file that was opened for read-only access.
__________________
fysiks is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 11-18-2011 , 19:08   Re: Read a line from a file and check
Reply With Quote #3

Rofl, perhaps. Still I remember that I used it on my Auto-Mix plugin, and it worked well.
But if you say so, how can I open a file which I can Read & write? "rw"?
__________________
My Projects:

Auto-Mix (Pug): 100%

Joined the Military (a soldier now) - Inactive
Diegorkable is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 11-19-2011 , 05:45   Re: Read a line from a file and check
Reply With Quote #4

Yeah sorry my bad, I thought it doesnt matter. The right flag would be "r+"
__________________
My Projects:

Auto-Mix (Pug): 100%

Joined the Military (a soldier now) - Inactive
Diegorkable 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 08:34.


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