解析C字符串
我对 C 很不熟悉。出现了一个逗号分隔的字符串,我需要理清它。一些位对应于数值,其他位对应于字等。
输入
char str_in;
str_in = "$GPRMC,114353.000,A,6016.3245,N,02458.3270,E,0.01,0,A*69";
输出
#include <string.h>
float lat, lon, time;
time = 114353.000;
lat = 60+(1/60)*16.3245; //Conversion to decimal degrees
lon = 024+(1/60)*58.3270;
所有间距保持不变。我一直在努力解决的部分是从纬度/经度中提取前两位/三位数字并以不同的方式对待它们。有人可以帮忙吗?
I'm quite unfamiliar with C. A comma sepearted string comes in and I need to untangle it. Some bits correspond to numerical values, others to words etc.
Input
char str_in;
str_in = "$GPRMC,114353.000,A,6016.3245,N,02458.3270,E,0.01,0,A*69";
Output
#include <string.h>
float lat, lon, time;
time = 114353.000;
lat = 60+(1/60)*16.3245; //Conversion to decimal degrees
lon = 024+(1/60)*58.3270;
All the spacings remain unchanged. The section I have struggled with is extracting the first two/three digits from the latitude/longitude and treating them differently. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用strtok。这是一个参考:
http://www.metalshell.com/source_code/31/String_Tokenizer.html
Uses strtok. Here's a reference:
http://www.metalshell.com/source_code/31/String_Tokenizer.html
http://nmea.sourceforge.net/#features
看起来不错。
http://nmea.sourceforge.net/#features
Looks good.
我可能会做这样的事情:
I'd probably do something like this: