static void getWeekNum(const char * weekstr,char *ret)
{
char strParaWeekE[] = "_Mon_Tue_Wed_Thu_Fri_Sat_Sun";
char strParaWeekN[] = "_1_2_3_4_5_6_7";
char strParaWeekC[] = "_一_二_三_四_五_六_日";
char *revbuf[8] = {0};
char *revbuf1[8] = {0};
char *revbuf2[8] = {0};
int num = 0;
split(strParaWeekE,"_",revbuf,&num);
split(strParaWeekN,"_",revbuf1,&num);
split(strParaWeekC,"_",revbuf2,&num);
char *returnValue;
int i = 0;
for(i = 0;i < num; i ++) {
if(strcmp(revbuf[i],weekstr)==0)
{
printf("==FindOut(%s=%s,%s)\n",revbuf[i],revbuf1[i],revbuf2[i]);
returnValue=revbuf1[i];//输出数字(如果提取数字用这句返回)
//returnValue=revbuf2[i]; //输出汉字(如果提取汉字用这句)
break;
}
}
ret=returnValue;
}
//代码可能没有优化,可交流改进
顶部声明一次函数,
主程序直接调用。
char *weeken;
getWeekNum("Thu",weeken);
忘记一个函数查找函数(补)
/**********************************
split参数:
src 源字符串的首地址
separator 指定的分割字符
dest 接收子字符串的数组
num 分割后子字符串的个数
************************************/
static void split(char *src,const char *separator,char **dest,int *num) {
char *pNext;
int count = 0;
if (src == NULL || strlen(src) == 0)
return;
if (separator == NULL || strlen(separator) == 0)
return;
pNext = strtok(src,separator);
while(pNext != NULL) {
*dest++ = pNext;
++count;
pNext = strtok(NULL,separator); //查找
}
*num = count;//数组总数
}
//---------------------------------------