Why string in "" work but String variable doesn't (IniFile library function)

Why this example work:

#include <IniFile.h>

void setup()
{

  const size_t bufferLen = 80;
  char buffer[bufferLen];
  IniFile ini("nazwapliku");
  ini.getValue("network", "mac", buffer, bufferLen);

}


void loop()
{
}

and this doesn't work:

#include <IniFile.h>

void setup()
{

  const size_t bufferLen = 80;
  char buffer[bufferLen];
  String fName = "nazwapliku";
  IniFile ini(fName);
  ini.getValue("network", "mac", buffer, bufferLen);

}


void loop()
{
}

and this one doesn't, how to use here variable instead of string in ""?
When I try to compile second one then I got error message:

Compiling debug version of 'IniFileExample' for 'Arduino/Genuino Uno'
 
IniFileExample.ino: In function void setup()
Error compiling project sources
 
Debug build failed for project 'IniFileExample'
IniFileExample.ino: 10:18: error: no matching function for call to 'IniFile::IniFile(String&)
   IniFile ini(fName)
IniFileExample.ino:10: note  candidates are
 
IniFileExample.ino: In file included from
IniFile.h:30: note  IniFile  IniFile(const char*, uint8_t, bool)
   IniFile(const char* filename, uint8_t mode = FILE_READ
IniFile.h:30: note    no known conversion for argument 1 from String to const char*
IniFile.h:13: note  constexpr IniFile  IniFile(const IniFile&)
   class IniFile {
IniFile.h:13: note    no known conversion for argument 1 from String to const IniFile&

If this can help in any way than I use this library -> GitHub - stevemarple/IniFile: Arduino library to parse ini files.

Use

  char fName[] = "nazwapliku";

and unless you have a 32 Bit Arduino or an ESP8266 forget about Strings altogether.

The function takes a character pointer, not a String object. You can store your value as a character pointer:

  char *fName = "nazwapliku";
  IniFile ini(fName);

or as a character array:

  char fName[] = "nazwapliku";
  IniFile ini(fName);

or put it in a character buffer (array):

  char fName[20];
  strncpy(fname, "nazwapliku", 20);
  IniFile ini(fName);

thanks :slight_smile: