#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "iostream"
int charcount(const char* str, char ch)
{
int count = 0;
for(int i=0;i<strlen(str);i++)
if(str[i] == ch)
count++;
return count;
}
void main(void)
{
char str[1024], Mask[16], **ch = 0, **bck = 0, **msk, counter = 0, amount = 0, size = 0, *cc = 0, ssize = 0, yesno = 0;
point:
system("cls");
printf("Type string:\n");
gets(str);
printf("Type mask:\n");
gets(Mask);
if((amount = charcount(str,'_') + 1) == 0) return;
ch = (char**)malloc(sizeof(char *) * amount);
bck = (char**)malloc(sizeof(char *) * amount);
msk = (char**)malloc(sizeof(char *) * strlen(Mask));
ch[0] = strtok(str, "_");
if(amount > 1)
{
for(int i=1;i<amount;i++)
{
char* cc = strtok(NULL, "_");
if(cc != 0)
ch[i] = cc;
}
}
if(charcount(Mask,'*') > 0)
{
size = Mask[0] == '*' ? charcount(Mask, '*') : charcount(Mask, '*') + 1;
msk[0] = strtok(Mask, "*");
if(size > 1)
{
for(int i=1, j = (int)(bool)msk[0];i<size;i++) {
char* cc = strtok(NULL, "*");
if(cc != 0)
{
ssize++;
msk[j++] = cc;
}
}
ssize++;
}
} else
msk[0] = Mask;
for(int i=0, countToRight = 0;i < amount; i++, countToRight = 0)
{
for(int j=0;j<ssize;j++)
{
if(strstr(ch[i], msk[j]))
countToRight++;
}
if(countToRight >= ssize)
{
bck[counter++] = ch[i];
}
}
if(counter != 0)
{
printf("Founds: ");
for(int i=0;i < counter;i++)
printf("%s %c ", bck[i], i == counter - 1 ? '\n' : '|');
} else {
printf("It is not contains.\n");
}
free(ch);
free(bck);
free(msk);
do
{
printf("\nDo you want to try it one more time? y/n : ");
yesno = tolower(getch());
printf("%c", yesno);
if(yesno == 'y')
goto point;
} while (yesno != 'y' && yesno != 'n');
}
Comments