Hello everyone, I need a little help from you guys.
I need to find the position of some strings , these strings store in a file named "queryfile" , from an other file named "datafile".
However, my programe just work on a single "word" , can't find the position of phrase or sentence.
Thank you so much!
my program
#include <stdio.h>
#include <string.h>
int main()
{
FILE *queryfile;
queryfile = fopen("op2query.txt","r");
FILE *datafile;
datafile = fopen("op2data.txt","r" );
int i = 1;
char word[99];
char search[99];
if(queryfile==NULL) {
printf("Error in reading Query File");
}
if(datafile==NULL) {
printf("Error in reading Data File");
}
while (!feof(queryfile)) {
fscanf(queryfile,"%s", &search);
while(!feof(datafile)){
fscanf(datafile,"%s", &word);
if (strcmp(word,search)==0){
printf("\n %i %s ", i, search);
rewind(datafile);
i=1;
break;
}
else i++;
}
}
fclose(datafile);
fclose(queryfile);
return 0;
}
op2query.txt
wisdom
season
age of foolishness
op2data.txt
it was the best of times it was the worst of times it was the age
of wisdom it was the age of foolishness it was the epoch of belief
it was the epoch of incredulity it was the season of light it was
the season of darkness it was the spring of hope it was the winter
of despair
result
18 wisdom
40 season
16 age
5 of
24 foolishness
THANK YOU!!!!!