字符串匹配问题
在str1中查找str2,若匹配,返回位置,否则返回-1程序输入以q结束
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 100
int main(void) {
int k;
int i,j;
char str1[N], str2[N];
int strsearch(char str1[], char str2[]);
/* 输入字符串给str1和str2, 当输入q时程序结束*/
while (1) {
scanf("%s", str1);
if (strcmp(str1, "q") == 0) break;
scanf("%s", str2);
k = strsearch(str1, str2);
printf("str1 = %s,str2 = %s, k = %d\n", str1, str2, k);
}
exit(0);
}
int strsearch(char str1[], char str2[]) {
int i,j;
int len1; //str1's length
int len2; //str2's length
int p;
len1 = strlen(str1);
len2 = strlen(str2);
for (i = 0; i <= len1 - len2; i++) {
p = i;
for (j = 0; j < len2; j++) {
if (_____________________________) {
p = -1;
break;
}
}
if (________________________________)
return p;
}
}
请帮忙做一下上面的两个空,谢谢