I have a file which contains certain text strings. I also have a char array which contains a query string. I have tokenised both strings to take one word at at a time but am unsure as how to compare the tokens to find out if there is a match between them. What I am trying to achieve is to search a file for a given text query, Code is as follows:
Any ideas on how to do this or improvements would be appreciated.
Code:
void smart_2(char *query, Res results[][100])
{
char string[] = "Distributed IR";
char *tokenPtr; //Token Ptr to query file
char *ttokenPtr; //Token Ptr to initial query string
fp = fopen("query_file.txt", "r"); //Query file
ffp = fopen("temp.txt", "w"); //Temp file to write tokens to
while(!feof(fp))
{
fprintf(ffp, "%s\n", " ", string);
tokenPtr = strtok(string, " ");
while(tokenPtr != NULL)
{
fscanf(fp,"%s", strtok);
fprintf(ffp, "%s\n", tokenPtr);
tokenPtr = strtok(NULL, " ");
}//while tokPtr
}//while eof
printf("%s\n", " ", query);
ttokenPtr = strtok(query, " ");
while(ttokenPtr !=NULL)
{
printf("%s\n", ttokenPtr);
ttokenPtr = strtok(NULL, " ");
}//while ttokPtr
}//smart_2