嵌入式 对字符串中特定字符计数以及据特定字符解析字符串

#include <stdio.h>
#include <string.h>

typedef struct{
    chardev1[32];
    chardev2[32];
    chardev3[32];
}JIPNC_ID;


int analyze_separator_num(char *src)
{
    char*cp_tmp;
    int counter= 0;

    cp_tmp =strtok(src, ";");
   if(cp_tmp)
    {
 printf("%s\n",cp_tmp);
 counter++;
    }

   while((cp_tmp=strtok(NULL,";"))!=NULL)
   
 counter++;
 printf("%s\n",cp_tmp);

    }

    returncounter;

}


void analyze_socket_data(char *dest,char *src)
{
    char*cp_tmp;
    int counter= 0;
    int i =1;

    cp_tmp =strtok(src, ";");
   if(cp_tmp)
    {
 strcpy(dest,cp_tmp);
 printf("dest  is%s\n",dest);
 counter++;
    }

   while((cp_tmp=strtok(NULL,";"))!=NULL)
   
 printf("cp_tmp is %s \n",cp_tmp);
 strcpy((dest+i*256),cp_tmp);
 counter++;
 i++;
    }

}


int test(char *kj)
{
   strcpy(kj,"44");
    return0;
}
int main()
{
    inttmp,i=0;
    charkj[1024] ="9;ipnc000000000001;ipnc000000000002;ipnc000000000003;ipnc000000000004;ipnc000000000005;ipnc000000000006;ipnc000000000007;ipnc000000000008;ipnc000000000009;";
    charsrc_tmp[1024];
    //chardata_tmp[10][256];
    charlm[256];

   strcpy(src_tmp,kj);
   printf("%s\n",kj);
    tmp =analyze_separator_num(kj);
    chardata_tmp[tmp][256];
   
   printf("src_tmp is :%s\n",src_tmp);

   analyze_socket_data( data_tmp,src_tmp);
    printf("thenumber of the ---;---  is %d\n",tmp);
   printf("strlen is %d\n",strlen(kj));
   printf("sizeof is %d\n",sizeof(kj));
   printf("%s\n",kj);


    for(i =0;i
    {
 strcpy(lm,data_tmp+i);
 printf("The %dth id is =%s\n",i+1,data_tmp+i);
 printf("The LM %dth id is = %s\n",i+1,lm);
 printf("THe LM %dth data lenght is =%d\n\n",i+1,strlen(lm));
    }

    return0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值