pushkar raj wrote: > I am dire straits regarding performance issue...But my project constraints > are such that I must solve this problem only through c language. > Pleas suggest a C code for the problem stated. > Its urgent.
Read in the first file in its entirety. Extract each and every line. You only need one malloc() call - just point to each entry in the original file and alter its contents to have a terminating null '\0' at the end of each line. Memory allocation is always a performance chewer. Read Safe C++ Design Principles' section on memory allocation - applies to C as well. You should make two passes over the data. The first pass determines how many lines are in the first file. Then you call malloc(). Then you fill the allocated memory with pointers to the data during the second pass. Sort the lines (qsort). This will be blazing fast - none of the data is actually moved - just swaps pointers. Read in the second file and search (bsearch) for the line. In essence, you've created the equivalent of a STL map (roughly - STL map is probably faster). Output data. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* VerifyMyPC 2.4 Change tracking and management tool. Reduce tech. support times from 2 hours to 5 minutes. http://www.CubicleSoft.com/VerifyMyPC/
