int Searchkeyword (unsigned int size, const char *keyword, FILE *fp)
{
char ckw[size];
unsigned int uikwlen=strlen(keyword)+1;
int i=0;
for(i=0;fgets(ckw,uikwlen,fp)!=NULL;i++)
{
if(strcmp(ckw,keyword) == 0)
{
//printf("fine_keyword=%s\n",ckw);
return 1; // Found
}
rewind(fp);
fseek(fp,i,SEEK_SET);
}
return 0; // Not Found
}
int main ()
{
FILE *fp=fopen("C:\\file.txt","r");
Searchkeyword (20,"keyword",fp);
fclose(fp);
system("pause");
return 0;
}
在檔案裡搜尋字串,不過好像用strstr()也行 =.=
沒有留言:
張貼留言