首页 > 代码库 > C语言字符串查找(gps的nmea协议解析)

C语言字符串查找(gps的nmea协议解析)

 main.c

#include<stdio.h>#include<string.h>#include <stdlib.h>#include <stdio.h>int main(){    char* str = "123,456,789,0123456,123456,0,09,10";    char sub[3];    int count = 0, index = 0;    for (index = 0; index < strlen(str); ++index){        if (str[index] == ,)            ++count;        if (count == 6)            break;    }    strncpy(sub, &str[index+1], 2);    sub[2] = \0;    printf(sub); //123,456,789    int n = atoi(sub);    printf("string = %s integer = %d\n", sub, n);}

end

 

C语言字符串查找(gps的nmea协议解析)