int split_str(char *buf,int length,int number,...)
{
va_list arglist;
int i = 0;
int num = 0;
char tmpstr[1024];
char msg[100];
char *ptr;
va_start(arglist, number);
if( ((strlen(buf)+length-1)/length) > number)
{
sprintf(msg,"实际分割数[%d]大于要求分割数[%d]!",
(strlen(buf)+length-1)/length,number);
ts(msg);
return(-1);
}
memset(tmpstr,'\0',sizeof(tmpstr));
while(*buf!='\0')
{
if((*buf & 0x80) == 0x80 ) /*是否为汉字*/
{
tmpstr[i++]=*buf;
buf++;
tmpstr[i++]=*buf;
buf++;
}
else
{
tmpstr[i++]=*buf;
buf++;
}
if(i>=length)
{
strcpy (va_arg(arglist, char *),tmpstr);
memset(tmpstr,'\0',sizeof(tmpstr));
i=0;
num++;
}
}
if(num strcpy (va_arg(arglist, char *),tmpstr);
va_end(arglist);
return 0;
}
阅读(1607) | 评论(0) | 转发(0) |