码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-12-23 19:10:33      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:color   c语言   bsp   amp   字符串查找   ++   index   end   printf   

 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协议解析)

标签:color   c语言   bsp   amp   字符串查找   ++   index   end   printf   

原文地址:http://www.cnblogs.com/dong1/p/6215772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!