Action()
{
char sub_str[]="2,4";
char result_str[]="";
get_strategy(sub_str,result_str);
return 0;
}
void split(char * p,char * str,char tmp[100][100]){
/*
传入一个数组进行p和一个以什么进行分割的str,返回切片后的值
*/
int i = 0, j = 0;
//申请内存空间
char *p1 = (char *)malloc(1024);
//strchr函数取分隔符之后的字符到p1
while((p1 = (char *)strchr(p, *str)) != NULL) //必须使用(char *)进行强制类型转换
{
//把截取分隔符之前的字符,赋值到二维字符数组
strncpy(tmp[i], p, strlen(p) - strlen(p1));
p = p1 + 1;//指针加1,去掉分隔符
//lr_output_message("%s\n", p1);
i ++;
}
strncpy(tmp[i], p, strlen(p));
}
int count_str(char *fastr, char *str, int length1, int length2)
{
int count = 0;
int i;
for (i = 0; i < length1; i++) //向后逐一比较
{
if (strncmp(fastr + i, str, length2) == 0) //核心部分!,length2为子串的长度,只进行字串长度的比较
count++;
}
return count;
}
void check_repeat(char * str){
//char str[]="\"2,9\",\"1,1\",\"2,8\",\"1,1\",\"3,4\"";
char tmp[100][100]={0};
int i=0;
int j=0;
split(str,"\",\"",tmp);
for (i=1;i<10;i=i+2) {
//lr_error_message( "the res message is #%s", tmp[i] );
for(j=i+2;j<10;j=j+2){
if (strcmp(tmp[i],tmp[j]) == 0) {
lr_error_message( "error appear!!!");
lr_error_message( "the cards message is #%s", str );
break;
}
}
}
}
int ReplaceStr(char* sSrc, char* sMatchStr, char* sReplaceStr)
{
int StringLen;
char caNewString[1024];
char* findPos;
merc_timer_handle_t timer_ReplaceStr = lr_start_timer();
//lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG ,"Notify:Function 'ReplaceStr' started.");
findPos =(char *)strstr(sSrc, sMatchStr);
if( (!findPos) || (!sMatchStr) ){
//lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG ,"Notify:Function 'ReplaceStr' ended with error!");
return -1;
}
while( findPos)
{
memset(caNewString, 0, sizeof(caNewString));
StringLen = findPos - sSrc;
strncpy(caNewString, sSrc, StringLen);
strcat(caNewString, sReplaceStr);
strcat(caNewString, findPos + strlen(sMatchStr));
strcpy(sSrc, caNewString);
findPos =(char *)strstr(sSrc, sMatchStr);
}
//lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG,"Result:%s",sSrc);
free(findPos);
//lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG ,"Notify:Function 'ReplaceStr' ended (Duration: %lf)",lr_end_timer(timer_ReplaceStr));
return 0;
}
void get_strategy(char sub_str[],char result_str[]){
char str[]="01234";
char str_tmp[]="";
int i = 0;
char tmp[100][100]={0};
split(sub_str,",",tmp);
while(strlen(tmp[i]) > 0)
{
memset(str_tmp,0,sizeof(str_tmp));
sprintf(str_tmp,"%s",tmp[i]);
ReplaceStr(str,tmp[i],"");
//lr_error_message( "the str is #%s", str );
i++;
}
memset(result_str,0,sizeof(result_str));
sprintf(result_str,"%c",str[0]);
for (i=1;i<strlen(str);i++) {
sprintf(result_str,"%s,%c",result_str,str[i]);
}
lr_error_message( "the result_str is #%s", result_str);
}