Excuse the thread subject, I don't think it properly explains what I want to do.
I'm using strtok to parse an incoming message which consists of a series of values delimited by a given character (semicolon in my case).
char input[length];
memcpy (input, payload, length );
char *parts[27];
char *ptr;
ptr = strtok(input, ";");
int i=0;
while (ptr !=NULL) {
parts[i++] = ptr;
ptr = strtok(NULL, ";");
}
for (int j=1;j<9;j++) {
weatherDay[h].temp[j-1] = atoi(parts[j]);
}
This works well, but in some cases there may be a missing value, in which case the service that sends the message inserts an 'x' into the message, like this:
2;x;x;x;4;5;6
In this case the value written into my struct weatherDay..temp[j-1] is a zero, presumably because when the atoi function cannot interpret an 'x', so it sets it to zero.
I was hoping to amend the above as follows, so that it sets the value to 256 where there is an 'x'.
(I can assume that if the temperature is set to 256 - a nonsense value - then either there's a missing value, or the atmospheric temperature is well past boiling point, either way I won't care)
</mark> <mark> for (int j=1;j<9;j++) { if (parts[j] == 120) { weatherDay[h].temp[j-1] = 256; } else { weatherDay[h].temp[j-1] = atoi(parts[j]); } }</mark> <mark>
where 120 is the ascii value of x. This doesn't compile, presumably because parts[j] is the pointer to the array?
How would I best go about doing this?