本文介绍了如何检索从AT CMGL响应的电话号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C语言编写的应用程序,从使用AT命令调制解调器读短信。一个典型的从调制解调器回应是这样的:

I have an application written in C that reads text messages from a modem using AT commands. A typical AT response from the modem looks like this:

+CMGL: 1,"REC READ","+31612123738",,"08/12/22,11:37:52+04"

的code为当前设置为只检索从该线,这是第一个数字的ID,并且它如此使用以下code:

The code is currently set up to only retrieve the id from this line, which is the first number, and it does so using the following code:

sscanf(line, "+CMGL: %d,", &entry);

下面,线是含有来自调制解调器的线路的字符阵列,和入口是其中的ID被存储的整数。我试图扩展这个code是这样的:

Here, "line" is a character array containing a line from the modem, and "entry" is an integer in which the id is stored. I tried extending this code like this:

sscanf(line, "+CMGL: %d,\"%*s\",\"%s\",", &entry, phonenr);

我想我会使用%* s到扫描第一对引号的文本,并跳过它,并读取下一对引号(电话号码)到phonenr字符数组的文本。

I figured I would use the %*s to scan for the text in the first pair of quotes and skip it, and read the text in the next pair of quotes (the phone number) into the phonenr character array.

这不工作(%* S显然写着REC和下一个%s不读什么)。

This doesn't work (%*s apparently reads "REC" and the next %s doesn't read anything).

这是额外的challange是文本并不局限于REC READ,它实际上可能是很多事情,也有文字的没有的在它的空间。

An extra challange is that the text isn't restricted to "REC READ", it could in fact be many things, also a text without the space in it.

推荐答案

我解决了,现在是一个具有以下code方式:

The way I solved it now is with the following code:

sscanf(line, "+CMGL: %d,\"%*[^\"]\",\"%[^\"]", &entry, phonenr);

此将首先扫描一个数量(%d)中,然后对于不是双引号字符的任意字符串(和跳过它们,因为星号的),并为电话号码它同样的

This would first scan for a number (%d), then for an arbitrary string of characters that are not double quotes (and skip them, because of the asterisk), and for the phone number it does the same.

不过,我不知道怎么还健壮,这是

However, I'm not sure yet how robust this is.

这篇关于如何检索从AT CMGL响应的电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:13