Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i compare the words in the f

Status
Not open for further replies.

niru1972

Programmer
Feb 3, 2001
6
US
how do i compare the words in the file, do i have to read the characters using getc till i get a space and put them in an array and then compare it with the next file

 
Storing them in a array might take loads of memory. Read word in the first file and another word from the second file and compare them. If not equal them break. Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
This is a typical problem in bank where the records from trasaction file is compared with master files . If your file is too large. Sort the second file first . Then pick one word from first file and make a binary search on the second file. This is the best way to do it in my opinion.

Siddhartha Singh
singh_siddhu@yahoo.com
Siddhartha Singh
siddhu_singh@bharatmail.com
siddhu.freehosting.net
 
If you're talking about a relatively small data set and the words in both files are not sorted already, you might want to consider the standard library functions qsort() and bsearch().

Yes, you have to write some routine for determining word boundaries and extract the words from each file on this basis. If the data set is fairly small, you might want to consider the standard library functions qsort() and bsearch().

To do it this way, read the words in one file into an array, qsort() it. Then move through the other file(s) and as you encounter each word, use bsearch() on the first array to see if the word was in the first file.

I'm not really sure if the above fits your specs as you weren't very specific to begin with.

HTH,

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top