AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reading string name from .ini (https://forums.alliedmods.net/showthread.php?t=326367)

Mikka 07-28-2020 11:58

Reading string name from .ini
 
Hello, I have configs/names.ini in my file

Example: "Name" "Prefix".

What's the easiest way to read it into a variable?

OciXCrom 07-28-2020 14:48

Re: Reading string name from .ini
 
Code:
ReadFile() {     new szFilename[256]     get_configsdir(szFilename, charsmax(szFilename))     add(szFilename, charsmax(szFilename), "/YourFile.ini")     new iFilePointer = fopen(szFilename, "rt")     if(iFilePointer)     {         new szData[64], szKey[32], szValue[32]         while(!feof(iFilePointer))         {             fgets(iFilePointer, szData, charsmax(szData))             trim(szData)             switch(szData[0])             {                 case EOS, ';': continue                 default:                 {
                    parse(szData, szKey, charsmax(szKey), szValue, charsmax(szValue))
                }             }         }         fclose(iFilePointer)     } }

Shadows Adi 07-28-2020 14:52

Re: Reading string name from .ini
 
Use a trie, you will get some troubles with dyn array.

fysiks 07-28-2020 20:05

Re: Reading string name from .ini
 
Quote:

Originally Posted by Shadows Adi (Post 2712053)
Use a trie, you will get some troubles with dyn array.

Without context, that shouldn't be the answer. It depends on what you want to do with it. While it might be likely that that is better, it's not a guarantee. Therefore, you should either provide at least one context in which it would be better to use a Trie and explain what you mean by "some troubles".


All times are GMT -4. The time now is 08:56.

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