#include <stdio.h>
void extract_with_sscanf() {
char str[] = "Temp:25.5C,Humidity:60%";
float temp;
int humidity;
if (sscanf(str, "Temp:%fC,Humidity:%d%%", &temp, &humidity) == 2) {
printf("Temperature: %.1f\n", temp);
printf("Humidity: %d\n", humidity);
} else {
printf("Extract failed!\n");
}
}
|