Hey folks,
I'm trying to create a function that reads a word one at a time. I have that function all ready to go, and I have a loop in my main that should terminate when there aren't any more words to be read. However, I'm having a hard time coming up with a condition that will satisfy that idea.
Here's the code for that looping structure. My get_word returns a char*.
Code:
FILE *f;
f = fopen(argv[1], "r");
char* word;
word = get_word(f);
while(word != NULL)
{
printf("%s\n", word);
word = get_word(f);
}
fclose(f);
My second question involves list intersection. I'm developing a simple search engine that queries an index for a given word and returns a list of files.
So given two char** lists, return the intersection in a char** format. It needs to be relatively fast as the point of this project is speed. I'm thinking I could qsort each list and then compare their contents, but that's technically O(n^2) with cutoff due to the sorted nature (every element still needs to look at every other element up to some point). If anyone knows any algorithms it'd be a great help!
Thanks all!