关闭

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

405人阅读 评论(0) 收藏 举报
分类:

#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;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1044636次
    • 积分:18254
    • 等级:
    • 排名:第522名
    • 原创:741篇
    • 转载:523篇
    • 译文:0篇
    • 评论:105条
    最新评论