exc/k&r/02-types-operators-and-exp/02-05.c

36 lines
743 B
C

#include <stdio.h>
int any(char s1[], char s2[]);
/* points out the place shere any char from snd arg occurs in fst arg */
int main(int argc, char *argv[])
{
if (argc <= 2) {
printf("error : expected two arguments\n");
return 1;
}
int i = any(argv[1], argv[2]);
if (i < 0)
printf("No occurence\n");
else {
printf("%s\n", argv[1]);
printf("%*s^\n", i, "");
}
return 0;
}
/* any: returns first location in string 's' where char from 'cs' occurs.
* returns -1 if none occur */
int any(char s[], char cs[])
{
int i, j;
for (i = 0; s[i] != '\0'; i++)
for (j = 0; cs[j] != '\0'; j++)
if (s[i] == cs[j])
return i;
return -1;
}