diff options
author | Michael Hunteman <michael@huntm.net> | 2023-07-04 17:03:53 -0500 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2023-07-06 17:23:45 -0500 |
commit | bfce8f0d0d828209ec0bec71371ee94a7ad62d3e (patch) | |
tree | bdf49ca788ca1ca030d5b1cccfd0c9dffeb3f69f /two/inc.c |
Initial commit
Diffstat (limited to 'two/inc.c')
-rw-r--r-- | two/inc.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/two/inc.c b/two/inc.c new file mode 100644 index 0000000..220f025 --- /dev/null +++ b/two/inc.c @@ -0,0 +1,45 @@ +#include <stdio.h> + +/* remove s2 chars from s1 */ +void +squeeze(char s1[], char s2[]) +{ + int i, j, k, b; + for (i = j = 0; s1[i] != '\0'; ++i) { + b = 0; + for (k = 0; s2[k] != '\0'; ++k) { + if (s1[i] == s2[k]) { + b = 1; + } + } + if (b == 0) { + s1[j++] = s1[i]; + } + } + s1[j] = '\0'; +} + +/* return first index in s1 where any char in s2 */ +int +any(char s1[], char s2[]) +{ + int i, j; + for (i = 0; s1[i] != '\0'; ++i) { + for (j = 0; s2[j] != '\0'; ++j) { + if (s1[i] == s2[j]) { + return i; + } + } + } + return -1; +} + +int +main() +{ + char s1[] = "foobar"; + char s2[] = "a"; + // squeeze(s1, s2); + printf("%d\n", any(s1, s2)); + return 0; +} |