summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorGentoo <installgentoo@endianness.com>2021-03-27 10:10:11 +1100
committerGentoo <installgentoo@endianness.com>2021-03-27 10:10:11 +1100
commit8541a54db15a1ee5086f01bf222a4dde70892a3b (patch)
tree2d77d36c29e61b7c349cfe5025b4163db2c32eb9 /main.c
downloadany-master.tar.gz
any-master.tar.bz2
any-master.zip
initial commitHEADmaster
Diffstat (limited to 'main.c')
-rw-r--r--main.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..64083c3
--- /dev/null
+++ b/main.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+/*
+Exercise 2-5. Write the function any(s1,s2), which returns the first location
+in the string s1 where any character from the string s2 occurs, or -1 if s1
+contains no characters from s2. (The standard library function strpbrk does
+the same job but returns a pointer to the location.)
+*/
+
+int any(char s0[], char s1[])
+{
+int i,j;
+for (i=0; s0[i] != '\0'; ++i)
+ {
+ for (j=0; s1[j] != '\0'; ++j){ if (s0[i] == s1[j]){return i;} }
+ }
+
+return -1;
+}
+
+int main(void)
+{
+printf("Position: %d\n",any("Test","wasdt"));
+return 0;
+}
+