Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- 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;i<size;i++) {
- char* cc = strtok(NULL, "*");
- if(cc != 0)
- {
- ssize++;
- msk[i] = cc;
- }
- }
- }
- } else
- msk[0] = Mask;
- for(int i=0, countToRight = false;i < amount; i++, countToRight = 0)
- {
- for(int j=0;j<ssize+1;j++)
- {
- if(strstr(ch[i], msk[j]))
- countToRight++;
- }
- if(countToRight >= ssize+1)
- {
- bck[counter++] = ch[i];
- }
- }
- if(counter != 0)
- {
- printf("Founds:");
- for(int i=0;i < counter;i++)
- printf("%s %c ", bck[i], i == counter - 1 ? '\0' : '|');
- }
- free(ch);
- free(bck);
- free(msk);
- getchar();
- }
- //=Sample of work=
- //
- //Type string:
- //This_Is_So_Long_String
- //Type mask:
- //*o
- //Founds:So | Long
Advertisement
Add Comment
Please, Sign In to add comment