Can I use this function to read a percent Value from an ini?

For example it would be something like this
if (Life drops below X percent)
(cDrinkaPotion)


The code I have so far only reads key values and such, I dont know how to read a number value..

bool readConfig ()
{
   char pFile[65535];
   strncpy_s(pFile, sizeof(pFile), szPath, sizeof(pFile));
   strcat_s(pFile, "\\mMap.ini");
   
   char nRet[65535];
   for (int i = 0; i < ArraySize(pEntries); i++)
   {
      GetPrivateProfileString(pEntries[i].pSection, pEntries[i].pKey, pEntries[i].pDefault, nRet, sizeof(nRet), pFile);
      if (pEntries[i].nType == CONFIG_BOOL)
         *(PBOOL)pEntries[i].nVar = getBool(nRet);
      else if (pEntries[i].nType == CONFIG_INT)
         *(PINT)pEntries[i].nVar = atoi(nRet);
      else if (pEntries[i].nType == CONFIG_STRING)
         strncpy_s((PCHAR)pEntries[i].nVar, sizeof((PCHAR)pEntries[i].nVar), nRet, sizeof(nRet));
   }
   return true;
}
#ifndef _CONFIG_H
#define _CONFIG_H

#define CONFIG_BOOL 1
#define CONFIG_INT 2
#define CONFIG_STRING 3

struct ConfigEntry {
   char* pSection;
   char* pKey;
   char* pDefault;
   int nType;
   LPVOID nVar;
};

bool readConfig ();
bool getBool(char* pRet);
VOID setConfig(char* pKey, char* pValue);

#endif

Retrieves an integer associated with a key in the specified section of an initialization file.

Not sure but I dont think that reads will read a percent, am I wrong??

Retrieves an integer associated with a key in the specified section of an initialization file.

Not sure but I dont think that reads will read a percent, am I wrong??

If you represent the values as integers (e.g. 0 .. 100), then it will work. So a working .ini file might look like ..

[section]
; with % -sign
value1=15%
; without % -sign
value2=99
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.