- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
//------------------------------- COMPARE -------------------------------------
// Function to compare two strings on a mask, using a question mark and
// asterisk.Question mark matches any single character. The asterisk matches
// any signs of a minimum length of zero. maximum length is not limited. Only
// the next character in the mask has a value when there is a coincidence.
int compare(const char pat[],const char text[],int rec_ex)
{
bool flag = false; // flag show if working on "star"
int pat_len ,txt_len, // lehtghs of pattern and text
flagc, // counter and position i check
shift=0; // shift position
pat_len = (int)strlen(pat); // get lehtgh of pattern
txt_len = (int)strlen(text); // get lehtgh of text
if(rec_ex == 1 || (!pat_len && !txt_len)) // check if have to check some
return(1); // if yes return 1 or if have exit
else if(rec_ex == pat_len) // else return 0 becose not check that
return (0); // return 0
for(flagc=0;flagc < pat_len;flagc++)
if(pat[flagc] == '*' && flagc + 1 == pat_len)
return(compare(pat,text,1));// end of check return 1
else if(pat[flagc] == '*')
flag = true; // start * compare set flag true
else if(pat[flagc] != '?')
{
if(toupper(pat[flagc]) != toupper(text[flagc+shift]) && !flag)
return(compare(pat,text,pat_len)); // bad char and no star
else if(toupper(pat[flagc]) == toupper(text[flagc+shift]) && flag)
flag = false; // set flag false position
else if(toupper(pat[flagc]) != toupper(text[flagc+shift]) && flag)
shift++;
}
else if(pat[flagc] == '?')
{ // check if have ? in star operation
if(toupper(pat[flagc]) == toupper(text[flagc+shift]) && flag)
flag = false; // set flag false position
else if(toupper(pat[flagc]) != toupper(text[flagc+shift]) && flag)
shift++; // add one more into shift
}
if((flagc+shift < txt_len && !flag) // text have nore chars and
|| (flagc+shift == txt_len +1 && pat[pat_len+1] != '*'))
return(compare(pat,text,pat_len)); // and next char in pattern no star
else
return(compare(pat,text,1)); // end of pattern and text
}
Вот на после завтра нужно по программированию функцию написать- рекурсивную для сравнения строк по маске.
Написал :-) якобы рекурсивную функцию :-)