Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <string.h>
- // Returns position of first met of any symbol from s2 in s1
- // Returns -1 if there`s no symbols from s2 in s1
- int any(char *s1, char *s2)
- {
- for (int i = 0; s1[i] != '\0'; i++)
- for (int j = 0; s2[j] != '\0'; j++)
- if (s1[i] == s2[j])
- return i;
- return -1;
- }
- int main(void)
- {
- char *str1 = malloc(sizeof(char) * 256);
- char *str2 = malloc(sizeof(char) * 256);
- strcpy(str1, "Mother washed the window");
- strcpy(str2, "tad");
- printf("%s\n%s\n%i\n", str1, str2, any(str1, str2));
- strcpy(str2, "ad");
- printf("%s\n%s\n%i\n", str1, str2, any(str1, str2));
- strcpy(str2, "d");
- printf("%s\n%s\n%i\n", str1, str2, any(str1, str2));
- free(str1);
- free(str2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement