C通过月份英文获取月份对应数字(2)

/********************************** 
	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;//数组总数
}  
//---------------------------------------

static void getMonthNum(const char * monstr,const char *ret)
{
  char strParaMonthE[] = "_Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec";
  char strParaMonthN[] = "_01_02_03_04_05_06_07_08_09_10_11_12";
  char *revbuf[13] = {0}; 
  char *revbuf1[13] = {0}; 
  int num = 0; 
  split(strParaMonthE,"_",revbuf,&num);
  split(strParaMonthN,"_",revbuf1,&num);
  
  char *returnValue;
  int i = 0;
  for(i = 0;i < num; i ++) {
    //printf("===>%s\n",revbuf[i]);
	if(strcmp(revbuf[i],monstr)==0)
	{
		printf("==FindOut(%s=%s)\n",revbuf[i],revbuf1[i]);
		returnValue=revbuf1[i];		
		break;
	}
  }
  ret=returnValue;
}

顶部声明,底部调用

    char *monthen;
    getMonthNum("Aug",monthen);

你可能感兴趣的:(网络笔记,学习笔记,物联网笔记)