[QUESTION] Divide string intio varialbes separated by COMA

How I can separate values from string into values? I am using an SD card module and 328p ATMEGA. I am able to read an especific string. But i want to separate the string into different variables.ç
EXAMPLE:

21:03:33 , 28

When 21:03:33 is TIME and 28 the temperature. I want to have two different varibles like:

Current Time = (and the time the temperature was recorded "21:03:33")
Temp = (the temperature "28")

Have a look at the parse example in Serial Input Basics

...R

Is the string in memory? It's ancient technology, but strtok() will do this.

sscanf() works

results

21:03:33 , 28
 h 21, m 3, s 33, x 28
char t [] = "21:03:33 , 28";

void setup() {
    Serial.begin(9600);

    Serial.println (t);
    int  h, m, s, x;
    sscanf (t, "%d:%d:%d , %d", &h, &m , &s, &x);

    char u [80];
    sprintf (u, " h %d, m %d, s %d, x %d", h, m, s, x);
    Serial.println (u);
}

void loop() {
}

If the string is always the same "XX:XX:XX , XX", then temperature is always at pos 11 of the string. And hour is always at pos 0, minute is always at pos 3, second is always at pos 6...

So in this case, you don't need strtok or sscanf, you can use these positions and atoi, like in this example WoCslr - Online C++ Compiler & Debugging Tool - Ideone.com

Do you need to access the values, or just print the data like below? Splitting the string in half is much easier than converting the strings to values:

Current Time =  (and the time the temperature was recorded "21:03:33")
Temp = (the temperature "28")

gcjr:
sscanf() works

results

21:03:33 , 28

h 21, m 3, s 33, x 28







char t [] = "21:03:33 , 28";

void setup() {
    Serial.begin(9600);

Serial.println (t);
    int  h, m, s, x;
    sscanf (t, "%d:%d:%d , %d", &h, &m , &s, &x);

char u [80];
    sprintf (u, " h %d, m %d, s %d, x %d", h, m, s, x);
    Serial.println (u);
}

void loop() {
}

it worked but just if the values are set. How do I store the function (because I am using an sd) myfile.read() into a variable?

didn't you say you had the info in a sting?

How I can separate values from string into values?
...
I am able to read an especific string

if you don't, then you need to read the data from the file into a buffer and then apply the above

or if the format is fixed and known for sure, then use the other methods... sscanf() takes a lot of flash memory.

In the new version I am working, I write and delate every X amount of time. This way when I read from the Sd there's just one string.

what's the point of the SD card then ?

Also then, what is the point of converting the data to human readable format, and converting it back again (which is apparently giving you some trouble)?