Quote:
Originally Posted by Sanjay Singh
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(szFilename, charsmax(szFilename))
add(szFilename, charsmax(szFilename), "/FileName.ini")
new iFilePointer = fopen(szFilename, "rt")
if(iFilePointer)
{
new szData[128]
new Array:myArray = ArrayCreate(128)
while(!feof(iFilePointer))
{
fgets(iFilePointer, szData, charsmax(szData))
trim(szData)
switch(szData[0])
{
case EOS, ';', '#': continue
case '[':
{
iSize = strlen(szData)
if(szData[iSize - 1] == ']')
{
szData[0] = ''
szData[i - 1] = ''
trim(szData)
console_print(0, "Current section: %s", szData)
}
else continue
}
default:
{
ArrayPushString(myArray, szData)
}
}
}
for(new i; i < ArraySize(myArray); i++)
{
server_cmd("say %a", ArrayGetStringHandle(myArray, i))
}
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(szData, szSetting, charsmax(szSetting), szValue, charsmax(szValue), szAnotherValue, charsmax(szAnotherValue))
Method 2: "setting" = "value"
PHP Code:
new szSetting[32], szValue[32]
strtok(szData, szSetting, charsmax(szSetting), szValue, charsmax(szValue), '=')
__________________