pass by character array paramater in sd.open

my code is like this:

char fname = {'x', '.', 't', 'x', 't', '\0'};
File vocFile = SD.open(fname, FILE_READ);

can anyone help me because i got this error, i want to use char array as paramater;

here is the error log:
Arduino: 1.8.5 (Windows Server 2008 R2), Board: "Arduino/Genuino Uno"

C:\Users\Administrator\Desktop\mike_wifi_vendo\mike_wifi_vendo.ino: In function 'void setup()':

mike_wifi_vendo:151: error: no matching function for call to 'SDLib::SDClass::open(char (*)[6], const uint8_t&)'

vocFile = SD.open(&fname, FILE_READ);

^

C:\Users\Administrator\Desktop\mike_wifi_vendo\mike_wifi_vendo.ino:151:42: note: candidates are:

In file included from C:\Users\Administrator\Desktop\mike_wifi_vendo\mike_wifi_vendo.ino:2:0:

C:\Users\Administrator\Documents\Arduino\libraries\SD\src/SD.h:79:8: note: SDLib::File SDLib::SDClass::open(const char*, uint8_t)

File open(const char *filename, uint8_t mode = FILE_READ);

^

C:\Users\Administrator\Documents\Arduino\libraries\SD\src/SD.h:79:8: note: no known conversion for argument 1 from 'char ()[6]' to 'const char'

C:\Users\Administrator\Documents\Arduino\libraries\SD\src/SD.h:80:8: note: SDLib::File SDLib::SDClass::open(const String&, uint8_t)

File open(const String &filename, uint8_t mode = FILE_READ) { return open( filename.c_str(), mode ); }

^

C:\Users\Administrator\Documents\Arduino\libraries\SD\src/SD.h:80:8: note: no known conversion for argument 1 from 'char (*)[6]' to 'const String&'

Multiple libraries were found for "SD.h"
Used: C:\Users\Administrator\Documents\Arduino\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
exit status 1
no matching function for call to 'SDLib::SDClass::open(char (*)[6], const uint8_t&)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

File vocFile = SD.open((const char *)fname, FILE_READ);

ok, thanx,, its working now..

What's wrong with the more conventional:

const char fname[] = "x.txt";

??

gfvalvo:
What's wrong with the more conventional:

const char fname[] = "x.txt";

??

By casting the non-const array to a const array, you are able to change, at run time, the contents of the array (the file name). By using const in the declaration of the array, you can no longer change the name at run time.

PaulS:
By casting the non-const array to a const array, you are able to change, at run time, the contents of the array (the file name). By using const in the declaration of the array, you can no longer change the name at run time.

Sorry, I was actually referring to this:

char fname[] = "x.txt";

verses the OP's code:

char fname[] = {'x', '.', 't', 'x', 't', '\0'};

Which is unnecessarily ugly, IMO.

But, if you want to change it at run-time, perhaps consider making it bigger just in case. Something like:

char fname[15] = "x.txt";

Actually, you shouldn’t even need to cast it. If the function is expecting a “const char *” and you pass it a “char *”, there should be no complaints. What gets the compiler upset is when you pass a “const char *” to a function expecting a “char *”. Permitting that would allow the function to change a “constant” via the pointer.

The only real problem in the original code was the presence of & in front of fname. The use or non-use of const is not a problem.