求指点词典查找函数
#include <stdio.h>#include <stdlib.h>
int main()
{
FILE * fp;
char word[20];
char find[20];
char ch;
int len,i;
printf("Please put in the word you want to look up:\n");
gets(word);
len=strlen(word);
if((fp=fopen("5000_words.txt","r"))==NULL)
{
printf("Can not open the file !!!\n");
exit(0);
}
fgets(find,len+1,fp); //求大佬指点把它改成只赋值每个换行符之后的len长度的字符给find字符数组
while(ch!=EOF)
{
if(strcmp(find,word)==0)
{
while(ch!='\n')
{
ch=fgetc(fp);
printf("%c",ch);
}
exit(0);
}
for(i=0;i<len;i++)
ch=fgetc(fp);
fgets(find,len+1,fp);
}
if(ch==EOF)
printf("Not found!!\n");
puts(find);
fclose(fp);
return 0;
}