Go Down

Topic: uSD Ethernet Shield (Read 817 times) previous topic - next topic

zEtA

Hi,

I have Ethernet W5100 with uSD-Card port. I want to create a file.txt inside SD, and I want his name have to be a char array. ┬┐Can I do this? I don't know what to do in this code line to change the word example for the array code[] and get in this case "11010114416886.txt"


Code: [Select]

char code[]={1, 10, 101, 144, 168, 86};
myFile = SD.open("example.txt", FILE_WRITE);


Thank's!
PD: I'm using SD.h library of Arduino 0022

zEtA


PaulS

Quote
Can I do this?

Yes.

Quote
I don't know what to do in this code line to change the word example for the array code[] and get in this case "11010114416886.txt"

You have an array of values. That the array type is char is not really relevant. You need to convert each value to a string, and append that value to a complete name.

Code: [Select]
String fileName = "";
char buffer[10];
for(int i=0; i<6; i++)
{
   sprintf(buffer, "%d", code[i]);
   fileName += buffer;
}
fileName += ".txt";


Then, you will need to extract the character array from the String object:
Code: [Select]
char name[40];
fileName.toCharArray(name, 40);


Then, use name in place of the hardcoded file name.
The art of getting good answers lies in asking good questions.

Go Up