Skip to content

Instantly share code, notes, and snippets.

@erenon
Created November 8, 2010 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erenon/668365 to your computer and use it in GitHub Desktop.
Save erenon/668365 to your computer and use it in GitHub Desktop.
pggyak kzh 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *filter(char *source, char *haystack) {
int i,j;
int nlen, cur, filter_flag;
char *nstr;
nlen = 0;
for (i = 0; source[i]; i++) {
for (j = 0; haystack[j]; j++) {
if (source[i] == haystack[j]) {
nlen++;
break;
/* elhagyhato, ha feltetlelzzuk,
hogy a haystack unique karakterekbol all */
}
}
}
nlen++; //closing 0
nstr = (char *)malloc(nlen *sizeof(char));
if (nstr == NULL) { return NULL; }
cur = 0;
filter_flag = 0;
for (i = 0; source[i]; i++) {
for (j = 0; haystack[j]; j++) {
if (source[i] == haystack[j]) {
filter_flag = 1;
break; //elhagyhato
}
}
if (!filter_flag) {
nstr[cur] = source[i];
cur++;
}
filter_flag = 0;
}
nstr[cur] = 0;
return nstr;
}
int main() {
char *str;
str = filter("fooobar", "ob");
printf("%s", str);
free(str);
str= NULL;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment