一、要求
解析gps坐标
Gps一帧数据,如下:
const char input[1024] ="$GNGGA,084852.000,2236.9453,N,11408.4790,E,1,05,3.1,89.7,M,0.0,M,,*48 $GNGLL,2236.9453,N,11408.4790,E,084852.000,A,A*4C $GPGSA,A,3,10,18,31,,,,,,,,,,6.3,3.1,5.4*3E $BDGSA,A,3,06,07,,,,,,,,,,,6.3,3.1,5.4*24 $GPGSV,3,1,09,10,78,325,24,12,36,064,,14,26,307,,18,67,146,27*71 $GPGSV,3,2,09,21,15,188,,24,13,043,,25,55,119,,31,36,247,30*7F $GPGSV,3,3,09,32,42,334,*43 $BDGSV,1,1,02,06,68,055,27,07,82,211,31*6A $GNRMC,084852.000,A,2236.9453,N,11408.4790,E,0.53,292.44,141216,,,A*7 5$GNVTG,292.44,T,,M,0.53,N,0.98,K,A*2D $GNZDA,084852.000,14,12,2016,00,00*48 $GPTXT,01,01,01,ANTENNA OK*35";
要求:
解析gps坐标
编写函数将里面的gps解析出来
二、实现代码
1.方法一:
#include<stdio.h>
#include<string.h>
//找到字符串的下标
int find_index(const char *s1,const char *s2)
{
int s1_len;
int s2_len;
int i,j;
s1_len = strlen(s1);
s2_len = strlen(s2);
for(i=0;i<s1_len;i++)
{
int t=i;
int cnt=0;
for(j=0;j<s2_len;j++)
{
if(s1[t] == s2[j])
{
t=t+1;
cnt++;
}
}
if(cnt == s2_len-1)
return t;
}
return 0;
}
//找A和E
int find_A_N_E(const char *s1,const char c, int index