sscanf语句读取 字符串信息
socket收到的字符串如下:符号《》内部,不含《》《
<GeocoderSearchResponse>
<status>0</status>
something
<formatted_address>geocode chinese address here</formatted_address>
</GeocoderSearchResponse>
》
如何从这个字符串里面提取status=0 geo_addr(formatted_address)=geocode chinese address here
C程序如下:VC
char data_buff[] = "<GeocoderSearchResponse>\r\n<status>0</status>\r\nsomething<formatted_address>geocode chinese address here</formatted_address>\r\n</GeocoderSearchResponse>\r\n";
int main(void)
{
int status = 1;
char geo_addr[100];
int ret;
ret = sscanf(data_buff,"%*[^<status>]<status>%d%[</status>]</status>%*[^<formatted_address>]<formatted_address>%d%[</formatted_address>]</formatted_address>",&status,geo_addr);
//这句话应该如何写
printf("ret from html: %d\n",ret);
printf("status from html: %d\n",status);
printf("geo_addr from html: %s\n",geo_addr);
return(0);
}