栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【无标题】C语言字符串分割

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【无标题】C语言字符串分割

c代码实现字符串分割 (通用于字节分割)

在公司使用过的
输入
nod : 开始分割的起始位置
source_str:代分割的字符串地址
dest_str : 保存分割的数组地址
dest_str_len:保存分割的数组长度
ch:分割的字符
return:分割以后新的起始位置

#include 
#include 
#include 
#include 
#include 
static int split_str(int nod, uint8_t *source_str, uint8_t *dest_str, int dest_str_len, uint8_t ch)
{
    if (NULL == source_str || NULL == dest_str)
    {
        return -1;
    }
    int len;

    len = strlen(source_str);
    int i;
    for (i = nod; i < len; i++)
    {
        if (*(source_str + i) == ch)
        {
            break;
        }
    }
    memcpy(dest_str, source_str + nod, i - nod);

    if ((i - nod) < dest_str_len)
    {
        dest_str[i - nod] = '';
    }

    if (i == len)
        return 0;
    else
        return (++i);
}
int main()
{
    char str_s[100] = "$GNGGA,, 024817.00,3109.95680723,N,12117.28029833,E,1,28,0.6,44.9440,M,0.0000,M,,*7D,,,";
    int nod = 0;
    char str_d[100] = {0};
    int i;
    for (i = 0; i < 20; i++)
    {
        nod = split_str(nod, str_s, str_d, sizeof(str_d), ',');
        printf("%sn", str_d);
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1029434.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号