#include <stdlib.h>
/**
*
* if find substring return 1,else return 0
*/
int bf_find(char *s1,char *s2){
int i=0,j=0;
while(s1 != '\0'){
while(s2 != '\0'){
if(s1 == s2){
j++;
if(s2 == '\0')
{
return 1;
}
}else{
break;
}
}
j=0;
i++;
}
return 0;
}
int main(){
int v;
char *s1 = malloc(sizeof(char)*100);
char *s2 = malloc(sizeof(char)*100);
if(s1 == NULL || s2 == NULL)
{
printf("apply mem fail\n");
exit(1);
}
printf("请输入字符串s1:");
scanf("%s",s1);
printf("请输入字符串s2:");
scanf("%s",s2);
v = bf_find(s1,s2);
if(v){
printf("%s中有%s的子字符串\n",s1,s2);
}else{
printf("不存在字符串\n");
}
free(s1);
free(s2);
return 0;
}
好好学习天天向上! 1
页:
[1]