开发者

how can i parse a string using c

Given below is my string

char test[1000]="$GPGSA,A,3,14,20,22,25,31,32,,,,,,,2.4,1.4,1.9*3A
    $GPGSV,4,1,16,31,76,060,35,14,28,070,34,20,32,309,32,32,61,309,32*72\n
    $GPGSV,4,2,16,25,21,053,29,24,37,258,29,23,14,277,27,12,,,21*44\n
    $GPGSV,4,3,16,22,13,133,20,11,20,272,,16,11,161,,30,,,*4F\
    n$GPGSV,4,4,16,29,,,,28,,,,27,,,,26,,,*7E\n
    $GPGGA,150427.8,4001.022852,N,10505.269674,W,1,06,1.4,1559.6,M,-21.0,M,,*53\n
    $PQXFI,150427.8,4001.022852,N,10505.269674,W,1559.6,35.12,25.46,2.05*4A\n
    $GPVTG,nan,T,nan,M,0.0,N,0.0,K,A*23\n
    $GPRMC,150427.8,A,4001.022852,N,10505.269674,W,0.0,,280611,,,A*50";

I want to get string

"$GPGGA,150427.8,4001.022852,N,10505.269674,W,1,06,1.4,1559.6,M开发者_运维技巧,-21.0,M,,*53\n"

from above big string using C Language.

Please help me out.


You say which line you want, but you didn't say why. If you say what it is about this line that makes it the line you are after, then I could comment on how you'd find it.

But basically, you'll probably want to separate the string into lines. You can use strtok() to break on \n. You can then examine the lines, one at a time.


This looks like GPS data to me and is used (and parsed) in many applications.

http://mbed.org/users/todotani/notebook/gps-nmea-parser/

http://www.edaboard.com/thread204021.html

You might be able to save yourself some time by re-using some other open source parsers.


The strstr() command, part of the standard C library, can be used to find a substring within a string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜