summaryrefslogtreecommitdiff
path: root/two/inc.c
diff options
context:
space:
mode:
Diffstat (limited to 'two/inc.c')
-rw-r--r--two/inc.c45
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;
+}