隨筆-144  評論-80  文章-1  trackbacks-0

          extern char *GetField(char *ibuf,char *ChrSet,int num)
          {
          int  i=0;
          static char tmp[256];
          char *pt,*pstr;

          pstr=(char *)malloc(strlen(ibuf)+1);
          strcpy(pstr,ibuf);
          for(i=0,pt=strtok(pstr,ChrSet);pt!=NULL;i++,pt=strtok(NULL,ChrSet))
          {
           if(i>=num||pt==NULL) break;
          }
          strcpy(tmp,pt);
          free(pstr);
          return(tmp);
          }

          例:
          char *pt;
          char buf[]="324324324|234324324|23432432432|23432432432|33333";
          pt=GetField(buf,"|",3);





          static void addArray(char *buff, char array[][MQ_ARRAY_LEN])
          {
            

              int index = 0;
              int i=0;

              char *pt,*pstr;
              char * ChrSet= ",";

              pstr=(char *)malloc(strlen(buff)+1);
              pstr = strcpy( pstr, buff);
              for(i=0,pt=strtok(pstr,ChrSet); pt!=NULL; i++, pt=strtok(NULL,ChrSet))
              {
                  if(pt==NULL) break;
                //  printf("dealing ... %s\n", pt);
                  strcpy(array[index],pt);
                  index++;
              }
              free(pstr);

          }

          posted on 2005-11-05 20:39 小力力力 閱讀(810) 評論(0)  編輯  收藏 所屬分類: C/C++
          主站蜘蛛池模板: 南丰县| 丽江市| 莱州市| 安丘市| 麻江县| 乐平市| 阳江市| 于田县| 蒙阴县| 松桃| 博白县| 永靖县| 潞西市| 博湖县| 积石山| 库尔勒市| 阳城县| 海兴县| 抚顺县| 东丰县| 宁晋县| 洛扎县| 绥宁县| 通河县| 石河子市| 柳江县| 象山县| 革吉县| 绥滨县| 久治县| 盱眙县| 武威市| 开原市| 南郑县| 集贤县| 安化县| 江油市| 石渠县| 泸西县| 克拉玛依市| 洛阳市|