#include <stdio.h>
int strinstr(const char *what, int length, char *in) {
int i = 0, ret = 0;
while (((what + i) && (in + i)) && (i < length)
&& (ret = (*(what + i) == *(in + i))))
++i;
return ret;
}
int main(void) {
char *In = "this is a test";
printf("strinstr(char *, int, char *) : %d\n", strinstr
("this", 4, In
)); printf("strinstr(char *, int, char *) : %d\n", strinstr
("is", 2, In
+ 5)); printf("strinstr(char *, int, char *) : %d\n", strinstr
("a", 1, In
+ 8)); printf("strinstr(char *, int, char *) : %d\n", strinstr
("test", 4, In
+ 10)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgc3RyaW5zdHIoY29uc3QgY2hhciAqd2hhdCwgaW50IGxlbmd0aCwgY2hhciAqaW4pIHsKICBpbnQgaSA9IDAsIHJldCA9IDA7CiAgd2hpbGUgKCgod2hhdCArIGkpICYmIChpbiArIGkpKSAmJiAoaSA8IGxlbmd0aCkgCiAgICAgJiYgKHJldCA9ICgqKHdoYXQgKyBpKSA9PSAqKGluICsgaSkpKSkgCiAgICArK2k7CiAgcmV0dXJuIHJldDsKfQoKaW50IG1haW4odm9pZCkgewogIGNoYXIgKkluID0gInRoaXMgaXMgYSB0ZXN0IjsKICBwcmludGYoInN0cmluc3RyKGNoYXIgKiwgaW50LCBjaGFyICopIDogJWRcbiIsIHN0cmluc3RyKCJ0aGlzIiwgNCwgSW4pKTsKICBwcmludGYoInN0cmluc3RyKGNoYXIgKiwgaW50LCBjaGFyICopIDogJWRcbiIsIHN0cmluc3RyKCJpcyIsIDIsIEluICsgNSkpOwogIHByaW50Zigic3RyaW5zdHIoY2hhciAqLCBpbnQsIGNoYXIgKikgOiAlZFxuIiwgc3RyaW5zdHIoImEiLCAxLCBJbiArIDgpKTsKICBwcmludGYoInN0cmluc3RyKGNoYXIgKiwgaW50LCBjaGFyICopIDogJWRcbiIsIHN0cmluc3RyKCJ0ZXN0IiwgNCwgSW4gKyAxMCkpOwogIHJldHVybiAwOwp9Cg==
strinstr(char *, int, char *) : 1
strinstr(char *, int, char *) : 1
strinstr(char *, int, char *) : 1
strinstr(char *, int, char *) : 1