Parse Data

I'm GETting data from Pachube, but not sure how to use it.
I've been told to

Parse the data down to just the CSV values and then use sscanf() to put the data into variables.

I haven't a clue how to do that.
The data I get is the following:
Content-Length: 7
Vary: Accept-Encoding

39,60,0
I need to have the last 3 numbers in variables like temperature=39.
Can anyone point me in the right direction?

Do you always get 4 lines of data? Is the data of interest always on the last line? Are there always 3 values?

Parsing data is a complex process. Finding the data of interest is the hardest part. If you know that the data of interest is always on the last line, and you've stored that data in an array of chars, sscanf is the correct function to use to separate it into discrete values.

The function takes 3 or more arguments. The first is the string to parse. The second is the parse format statement. It would look like this to parse three ints: "%d,%d,%d". The remaining argument(s) are the variables to populate with the values parsed.

I actually get more than 4 lines of data, but I always have 3 values and they are always on the last line. Anyone have and examples?

remaining argument(s) are the variables to populate with the values parsed.

The remaining argument(s) are pointers to the variables to populate with the values parsed.

Split the string with numbers into 3 separate strings (look for "," character in for cycle) and convert them into numbers (atoi, atol, atof ... functions in C).

Something like this?

void GetData()
{
while (i<data.length():wink:
{
string = string []++;
}
sscanf (string,"%d %d %d",temp1, temp2, sun);
}
}

The sscanf statement should read:

sscanf(string, "%d,%d,%d", &temp1, &temp2, &sun);

The variables temp1, temp2, and sun need to be defined as int.

You probably want to do something with the values after you get them. The function shown does not, so unless they are global variables, the data will be lost when the function ends.

The while statement is missing a closing ). The variables i and data are not defined here, so whether or not the while makes sense, or not, is unknown to us.

The string = string[]++; statement contains many errors. Without knowing what string is, and what you meant to do, I can not suggest a correct statement.

atoi() and friends is to be avoided as they provide no way to test for success.

When using the *scanf family, you should be checking the return value.