4 years, 8 months ago.

Check if key is found in IniFileLib

Dear experts

I am using the IniFileLib (https://os.mbed.com/users/rinosh2/code/IniFileLib/) library to read my .ini file.

How do I know if a key is found or not in an if statement?

Kind regards

1 Answer

4 years, 8 months ago.

Hi Jordy,

You can use this API IniFile::Status IniFile::get(const char* key, char* ret, int ret_size() to get the key, and check the error code returned.

// error code
    typedef enum {
        S_SUCCESS,
        S_OPEN_ERROR,
        S_NOT_OPENED,
        S_NO_KEY,
        S_BUFFER_TOO_SHORT,
        S_FORMAT_ERROR,
    } Status;

Regards, Desmond

Hi, thanks for your reply!

I tried to do this, but it didn't work for me.

I tried this:

code

int number;
if(IniFile::getval("/local/file.ini", "Number", number) == IniFile::Status::S_NO_KEY)
{…}

What did I do wrong?

Kind regards

posted by Jordy V 29 Aug 2019

What do you mean it didn't work for you? Compilation failure or run time failure? Do you have any logs?

Thanks, Desmond

posted by Desmond Chen 30 Aug 2019