learningc/chapters/2/exercises/5.c

20 lines
438 B
C

#include <stdio.h>
int any(char s1[], char s2[]);
int main() {
printf("%i\n",any("tester","r"));
return 0;
}
int any(char s1[], char s2[]) {
int i,j,k,s; // i is writing position and k is reading position
for (i = 0, k = 0; s1[k] != '\0'; k++) {
for (s = 0, j = 0; s2[j] != '\0'; j++) {
// We check if we have a disallowed character and break if it is the case
if (s1[k] == s2[j]) {
return ++k;
}
}
}
return -1;
}