这个代码运行出问题,有没有大神看看哪儿出错了啊(小白求助)
//字符串暴力匹配
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//**********************************************************************
typedef char DATA;
//**********************************************************************
int BF(char a[],char b[]);
void ceshi();
//***********************************************************************算法
int BF(char a[],char b[]){
int i=0,j=0;
printf("the host string\n");
printf("%s\n",a);
printf("the second string\n");
printf("%s\n",b);
while(a[i]!='\0'&&b[j]!='\0'){//两个字符串结束时退出循环
if(a[i]==b[j]){
i++;//主串的数组位置
j++;//副串的数组位置
}
else{
i=i-j+1;//主串位置回溯
j=0;//副串数组位置返回开头
}
if(a[i]=='\0'){
printf("\n");
printf("It's successful\n");
return (i-j);//返回主串数组位置
}
if(b[j]=='\0'){
printf("\n");
printf("error!!!\n");
break;//退出循环
}
}
printf("\n");
return -1;//返回-1
}
//**************************************************************通过动态数组的形式把输入的数组返回给bf函数
char *shuzu(char *str){
str=(char *)malloc(sizeof(char));
int len;
if(str==NULL)
exit(-1);
scanf("%s",str);
getchar();
len=strlen(str);
printf("this is your string\n%s,and your string lenth is %d\n",str,len);
printf("\n");
return str;
free(str);
}
//***************************************************************
void ceshi(){
char *a=NULL,*b=NULL;
printf("please scanf your host string\n");
a=shuzu(a);//输入主串
printf("\n");
printf("please scanf your second string\n");
b=shuzu(b);//输入副串
int i;
i=BF(a,b);//通过bf函数进行匹配,然后返回主串中副串的数组位置
printf("%d\n",i);
}
//*********************************************************
int main(){
void ceshi();
}