Created
November 8, 2010 22:11
-
-
Save erenon/668365 to your computer and use it in GitHub Desktop.
pggyak kzh 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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