Raised This Month: $ Target: $400
 0% 

Need to read string from file and store it in array


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
B34ST
Junior Member
Join Date: May 2014
Old 06-09-2014 , 09:17   Need to read string from file and store it in array
Reply With Quote #2

Guys i need to read list of strings from file and want to store it in array but im unable to do that

PHP Code:
const MAX_LEVELS 100;
enum _:LevelData {
    
LD_Level 
   
}; 


   
new 
data[LevelData]  

public 
plugin_init() 

CreateNamesArray() 



public 
CreateNamesArray() 
{
get_configsdir(g_szLevFilecharsmax(g_szLevFile));  //gets addons/amxmodx/configs directory
format(g_szLevFilecharsmax(g_szLevFile), "%s/ps_levels.ini"g_szLevFile); //formats the file name for the Weapons order INI
g_FilePointer fopen(g_szLevFile"r"); //Opens the file  
tlevels ArrayCreate(LevelData);



new 
szData[32];
new 
lev[32]
if(
g_FilePointer//Makes sure the files open
    
{
        while(!
feof(g_FilePointer))
        {
            
fgets(g_FilePointerszDatacharsmax(szData)); //Reads a line of the file
            
trim(szData); //Removes '^n' new line character from the end of the line
            
if(containi(szData";") != -1//Checks to see if its a comment and then ignores it
                
continue;  
            
parse(szDatalev31
            
data[LD_Level] = str_to_num(lev);  
            if(
sizeEntries MAX_LEVELS
            {
                
// add it to the end
                
ArrayPushArray(tlevelsdata); 
                
sizeEntries++;
            }
        }
    }
fclose(g_FilePointer);    
        
}     
public 
show_xp(id)
{
ArrayGetArray(tlevelsgxp[id], data); 
client_print_color(id,id,"your class is %s",data[LD_Level] ) 

This is my code basically what i want is instead of creating an array of level classes like
new const Prefix[MaxLevels +2][] =
{
"Newbie", // 0
"Noob", // 15
"Playah", // 40
"Semi-Pro", // 75
"Senior", // 130
"PIMP", // 200
"GangLeader", // 300
"Global Assasin", // 450
"Chuck Norris", // 650
"Veteran", // 1000

}

I want this to be written in a ini file so that anyone can modify it nd i want to read that ini file den store the class names in an array like the above array has 9 classes for 9 levels so i want to display respective class names for respective levels so pls suggest modification in my code
B34ST 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 09:39.


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