Raised This Month: $ Target: $400
 0% 

How do you read something from a file. Ini?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 05-03-2010 , 13:40   Re: How do you read something from a file. Ini?
Reply With Quote #5

reading from file is easy:
PHP Code:
#include <amxmodx>
#include <amxmisc>


public func(){
    new 
path[128], fhcache[128]
    
get_configsdir(path127)
    
format(path127"%s%s"path"/myfile.ini")
    
//with this it will try to open file: amxmodx/configs/myfile.ini

    
if(!file_exists(path)){ //check if file exists
        
log_amx("Error: file does not exist (%s)."path)
        return
    }

    
fh fopen(path"rt"//open text ("t") file for reading ("r")
    
if(!fh){ //check if we got proper file handle
        
log_amx("Error: Could not open file (%s)."path)
        return
    }

    new 
example_counter
    
while(!feof(fh)){ //loop until file handle points at the end of file
        
fgets(fhcache127//read next line from file and store it in "cache"

        //example count lines and print them in server console using log_amx:
        
example_counter++
        
log_amx("loaded line number %d: %s"example_countercache)

    }

    
fclose(fh)  //close file

__________________
Impossible is Nothing
Sylwester is offline
 



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 03:35.


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