从c中的长字符串获取电话号码作为字符串

时间:2016-03-28 12:02:59

标签: c substring

我有Telit调制解调器,我想获取sim电话号码,Telit返回字符串如:

"+CNUM: "","+123456789123456",**145**ok"

Or : "+CNUM: "","+123456789123456",**129**ok"

仅与数字145(International), 129(National)不同。

我想只得到这个号码:+123456789123456,没有" + CNUM:"","没有,129。

我试过了:

responseBuffer ="+CNUM: "",""+123456789123456"",145";
sscanf(responseBuffer,"%*s %s",phoneNum);   // cut the beginning

如何摆脱字符串的重置,从','到结尾的字符?

2 个答案:

答案 0 :(得分:0)

感谢@JoachimPileborg,我使用了strtok

responseBuffer ="+CNUM: "",""+123456789123456"",145";
token = strtok(responseBuffer, ",");
if( token != NULL ) 
  token = strtok(NULL, ",");
strcpy(phoneNum,token);

答案 1 :(得分:0)

您可以尝试搜索' +' char并在找到它之后将电话号码存储到字符串指针中。

storePhoneNumber(const char* input, char* dest){
//loop over the input
//look for '+' char
//when found start to store numbers on by one
// put it in to the dest
}
相关问题