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
小力力力 阅读(805)
评论(0) 编辑 收藏 所属分类:
C/C++