Raised This Month: $ Target: $400
 0% 

read file


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-08-2020 , 10:05   Re: read file
Reply With Quote #10

Quote:
Originally Posted by Sanjay Singh View Post
fixed bdw what can be used then instead of parse?
Nothing. Delete the line, it serves no function here.

Sections:

PHP Code:
ReadFile()
{
    new 
szFilename[256]
    
get_configsdir(szFilenamecharsmax(szFilename))
    
add(szFilenamecharsmax(szFilename), "/FileName.ini")

    new 
iFilePointer fopen(szFilename"rt")

    if(
iFilePointer)
    {
        new 
szData[128]
        new Array:
myArray ArrayCreate(128)

        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)

            switch(
szData[0])
            {
                case 
EOS';''#': continue
                case 
'[':
                {
                    
iSize strlen(szData)

                    if(
szData[iSize 1] == ']')
                    {
                        
szData[0] = ''
                        
szData[1] = ''
                        
trim(szData)

                        
console_print(0"Current section: %s"szData)
                    }
                    else continue
                }
                default:
                {
                    
ArrayPushString(myArrayszData)
                }
            }
        }

        for(new 
iArraySize(myArray); i++)
        {
            
server_cmd("say %a"ArrayGetStringHandle(myArrayi))
        }

        
ArrayDestroy(myArray)
        
fclose(iFilePointer)
    }

If you have settings in your file, this is how you would approach them:

Method 1: "setting" "value" "another value"

PHP Code:
new szSetting[32], szValue[32], szAnotherValue[32]
parse(szDataszSettingcharsmax(szSetting), szValuecharsmax(szValue), szAnotherValuecharsmax(szAnotherValue)) 
Method 2: "setting" = "value"

PHP Code:
new szSetting[32], szValue[32]
strtok(szDataszSettingcharsmax(szSetting), szValuecharsmax(szValue), '='
__________________

Last edited by OciXCrom; 01-08-2020 at 10:08.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
 



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 02:56.


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