I am trying to build an incremental file name by first making the string, then calling toCharArray, which works for one file, but when I try to make a second file, the first file name gets the second file name added to it and it throws a write error.
Here is the code and the subsequent serial output:
As you can see, the filename is fine until I call toCharArray on errfile.
Do I need to clear some bits somewhere? What makes it more confusing is I set the length of the filename array to 11 manually, so I don't understand how it will hold more chars.
You've defines filenameArray to hold 10 characters. Why are you lying to this function, telling it that the array can hold 11 characters PLUS a terminating NULL?
When I ran it with 10, it dropped off the last 't', so I changed it to 11. I also set it to filename.length() and added a blank space after ".txt" and it works on it's own. The other way that I've done it is filename.length() + 1.
Hey, great advice! I set both array sizes to my shoe size (12) and made the second argument in the toCharArray() method 12, and it worked!
I am still confused as to why it has to be 12, even with a stop bit. There are 10 characters in the name, so does this just chop off the last character?
I am still confused as to why it has to be 12, even with a stop bit. There are 10 characters in the name, so does this just chop off the last character?
The second argument tells it how much space there is in the array, NOT the number of bytes to extract. The method already knows how many characters there are in the String. The function will extract all of them, if that number is smaller than the destination array size. If it is not, it will truncate the String.
There are 10 characters in the name. With the terminating NULL, the array size must be at least 11. Good thing you don't have small feet. 8)