I read char string[] = {"-1200,2000,3300,-4150,5150,6000"}; from an SD card. Then I parse each element and store them into an integer array. I do some calculations with the integers and update my integer array.
Now I need to convert all the elements from my integer array to a char array to save it on the SD card.
int nums[3] { -150, -120, -170};
String string[] = {"-110,-123,-177"};
byte n;
byte s = 0;
String myString;
int myInt;
char buffer[5];
void setup() {
Serial.begin(9600);
int sizeString = (sizeof(string));
for (n = 0; n < 3; n++) {
myInt = nums[n];
sprintf(buffer, "%d", myInt); /*convert int to a string and store inside a buffer*/
myString = String(buffer);
Serial.print("Integer Converted to String: ");
Serial.println(myString); /*Print string value on serial monitor*/
}
}
void loop() {
}
But now I don't know how to replace the old strings with the new strings (numbers) into my string array.
yes, it writes integers as binary data. Any data types - ints. longs, chars.... are represented as binary inside the controller.
You don't need a separator when storing/reading binary data, because the data has fixed size. Therefore, to read 3 ints you need to read 3 times of int data size bytes:
Sorry, still no data on the serial monitor. I checked the SD card, it's ok.
I tried an example from SD library, works fine.
I looked at the SD card on PC, There's no "example.dat" file on the card.
Great ! It works fine. Thank you very much.
This is the "best" solution, without writing text files, parsing, transforming text to integer, etc. . Kudos.