看懂最重要,不要照抄...
#include<stdio.h>
#include<string.h>
int main(void)
{
char name[15],keyword[100],str[50][100];
printf("Enter the original text file : ");
scanf("%s",name);
printf("Enter the word to be found : ");
scanf("%s",keyword);
FILE *fp;
fp=fopen(name,"r");
char ch;
int i,match=0,point=0;
for(;;match=0)
{
for(i=0;;i++)
{
fscanf(fp,"%s",str[i]);
if( strcmp(str[i],keyword) == 0)
match++;
ch=getc(fp);
if( ch == '\n')
break;
else if( ch == EOF )
{
point=1;
break;
}
}
if(match != 0)
{
for(int temp=0;temp<=i;temp++)
{
printf("%s ",str[temp]);
}
printf("\n");
}
if(point == 1)
break;
}
fclose(fp);
return 0;
}
--
我絕對沒有開過BENZ...
--
※ 發信站: 批踢踢實業坊(ptt.twbbs.org)
◆ From: IP035.dialup.nt