#include "string.h"
#include "ctype.h"
#include "stdio.h"
search(char pd[])
{FILE *fp;
int time=0,i=0,j=0,add[80],k=0,m;
char *ch,
str[900];
m=strlen(pd);
if((fp=fopen("haha.txt","r"))==NULL)
{
printf("Cannot open this file\n");
exit(0);
}
for(;!feof(fp);i++)
{
str[i]=fgetc(fp);
if(tolower(str[i])==tolower(pd[k]))
{k++;
if(k==m)
if(!isalpha(i-m)&&!isalpha((str[i++]=fgetc(fp))))
{
time++;
add[j]=i-m+1;
j++;
k=0;
}
else k=0;
}
}
if(time)
{
printf("The time is:%d\n",time);
printf("The adders is:\n");
for(i=0;i<j;i++)
printf("%5d",add[i]);
if(i%5==0)
printf("\n");
getch();
fclose(fp);
}
else
printf("Sorry!Cannot find the word(^_^)");
}
main()
{
char pd[10],choose='y';
int flag=1;
while(flag)
{printf("In put the word you want to seqarch:");
scanf("%s",pd);
search(strlwr(pd));
printf("\nWould you want to continue?(Y/N):");
getchar();
scanf("%c",&choose);
if((tolower(choose))=='n')
flag=0;
else flag=1;
}
printf("Thanks for your using!Bye-bye!\n");
getch();
}