Raised This Month: $ Target: $400
 0% 

Need to read string from file and store it in array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
B34ST
Junior Member
Join Date: May 2014
Old 06-09-2014 , 09:04   Need to read string from file and store it in array
Reply With Quote #1

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:
 
B34ST is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-09-2014 , 09:12   Need to read string from file and store it in array
Reply With Quote #2

What did you try?
__________________
Arkshine is offline
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 #3

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
B34ST
Junior Member
Join Date: May 2014
Old 06-09-2014 , 09:18   Re: Need to read string from file and store it in array
Reply With Quote #4

i have declared all global variables but not metioned in the code
B34ST is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-09-2014 , 09:46   Re: Need to read string from file and store it in array
Reply With Quote #5

Oops, tried to move Arkshine's post from the other thread here and delete it because it was a duplicate, however the "Move" option somehow changed the thread author. Can anyone fix this?
Backstabnoob is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-09-2014 , 09:59   Re: Need to read string from file and store it in array
Reply With Quote #6

I've unucked and merged both threads, but not sure what other thread you're talking about.
__________________
Arkshine is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-09-2014 , 10:00   Re: Need to read string from file and store it in array
Reply With Quote #7

Thanks. The one you merged it with seemed like a duplicate to me (except without any actual content), so no clue what was going on there.
Backstabnoob is offline
B34ST
Junior Member
Join Date: May 2014
Old 06-09-2014 , 10:10   Re: Need to read string from file and store it in array
Reply With Quote #8

Guys help me :/ need help un dis code
B34ST is offline
Reply


Thread Tools
Display Modes

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