i am trying to use variables for filenames instead of hardcoded ones to be used like dataFile = SD.open(filename);
i understand that the filename variable can be declared as a string (type char) or as a String object (type String)
i think i can understand the String object usage as i have had experience with string manipulation in BASIC with $A = $B + "C" and the like.
however, if the filenames are fixed (eg. choosing from a menu of a limited set) then one should use the char type since this uses less memory, right ?
my problem now is getting the pairing of the variable and its usage in the function.
working from the examples on the Arduino Reference page;
IF
char* myStrings[]={"This is string 1", "This is string 2", "This is string 3",
"This is string 4", "This is string 5","This is string 6"};
THEN
for (int i = 0; i < 6; i++) { Serial.println(myStrings[i]); }
results in each sentence being listed.
but
IF
char myStrings[]={"This is string 1 This is string 2 This is string 3 This is string 4 This is string 5 his is string 6"};
THEN
for (int i = 0; i < 6; i++) { Serial.println(myStrings[i]); }
only results in This i
ie. each letter in the single string is viewed as a member of that array.
so far so good - but when i try to start using them in a function like so;
declaration and usage:
char file2use[13]="what2prn.txt";
readFile(file2use[13]);
with the function:
void readFile(char filename) {
dataFile = SD.open(filename);
...
}
then i get the error message; invalid conversion from 'char' to 'const char*'
(i'm probably still not quite grasping the usage of the '*' as an array pointer(?))
i tried changing the function to
void readFile(char filename[13]) {
dataFile = SD.open(filename[13]);
...
}
but then get the error; invalid conversion from 'char' to 'char*'
![]()
could you please point out where i am going wrong with this ?