sscanf语句读取字符串信息
sscanf语句读取字符串信息串口收到的字符串如下:符号《》内部,不含《》
《
AT+CMGR=23
+CMGR: "REC UNREAD","1008611","","14/12/22,17:29:02+32"
60A8672C6708901A4FE18D3900320034002E003700345143FF0C4F59989D00310031002E003800385143FF0C52694F59901A8BDD5206949FFF1A54085BB66B224F5900310039003500355206949FFF0C00567F5153056708595799104F5900310030003000305206949F300252694F594E0A7F516D4191CF002F65F6957FFF1A770151850033
》
现在我想从这个长字符串里面读取信息
char Msg_REC[10] = {0};//短信标识,是否已经读取过此短信 此字符串应为“REC UNREAD”
char Msg_tele_no[11] = {0};//短信号码 此字符串应为"1008611"
char Msg_time[20] = {0};//短信接收时间 此字符串应为"14/12/22,17:29:02+32"
char Msg_content[512] = {0};//短信内容,unicode编码形式 此字符串应为60A8672......
我写的C解析程序如下 VC:
char data_buff[] = "AT+CMGR=23\r\n+CMGR: \"REC UNREAD\",\"1008611",\"\",\"14/12/22,17:29:02+32"\r\n60A8672C6708901A4FE18D3900320034002E003700345143FF0C4F59989D00310031002E003800385143FF0C52694F59901A8BDD5206949FFF1A54085BB66B224F5900310039003500355206949FFF0C00567F5153056708595799104F5900310030003000305206949F300252694F594E0A7F516D4191CF002F65F6957FFF1A770151850033\r\n";
char Msg_REC[10] = {0};//短信标识,是否已经读取过此短信 此字符串应为“REC UNREAD”
char Msg_tele_no[11] = {0};//短信号码 此字符串应为"1008611"
char Msg_time[20] = {0};//短信接收时间 此字符串应为"14/12/22,17:29:02+32"
char Msg_content[512] = {0};//短信内容,unicode编码形式 此字符串应为60A8672......
int main(void)
{
ret;
ret = sscanf(data_buff,"%*[^\"]%s\",\"%s\",\"\",\"%s\"%s",Msg_REC,Msg_tele_no,Msg_time,Msg_content);
printf("ret from CMGR: %d\n",ret);//打印出匹配的参数个数
printf("Msg_REC from CMGR: %s\n",Msg_REC);
printf("Msg_tele_no from CMGR: %s\n",Msg_tele_no);
printf("Msg_time from CMGR: %s\n",Msg_time);
printf("Msg_content from CMGR: %s\n",Msg_content);
return(0);
}
字符串定义char data_buff[]应该是正确的吧?
sscanf函数如何读取字符串里的信息?