Created
August 4, 2024 10:56
-
-
Save giorgi568/37bc8e4f9416a26b78c13e02d6012bdf to your computer and use it in GitHub Desktop.
the c programming language book, exercise 2-5
This file contains hidden or 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> | |
| /* | |
| this is supposed to return first location in | |
| string s1 where any character from the string | |
| s2 occurs, or -1 if no such occurances exist. | |
| */ | |
| int any(char s1[], char s2[]); | |
| int any(char s1[], char s2[]){ | |
| int i, l; | |
| for(i = 0; s1[i] != '\0'; i++){ | |
| for(l = 0; s2[l] != '\0'; l++){ | |
| if(s1[i] == s2[l]){ | |
| return i; | |
| } | |
| } | |
| } | |
| return -1; | |
| } | |
| void main(){ | |
| char s1[] = "car"; | |
| char s2[] = "r"; | |
| printf("%d\n", any(s1, s2)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment