Table Lookup Processing
I am in need of a way to read two files as input, and produce an output file. One file has a string in it that is a code ..... and the second file is a file containing a translation table for that code.
I need to read the first file, pull off the code from that file, then find the corresponding record containing that code in the second file, and then retrieve the description associated with that code from the second file.
I have been thinking of a few ways I could do this:
Read the second file (translations file) into a two dimensional array of structures, which contain multiple occurances of the following:
Then, read the first file, obtain the code, then perform a loop reading through the array of code/descriptions, until I find a match. Then I will have the correct description for my output file.
Perform a dynamic indexed read to the second file, whose key would be the code, and get the description that way.
As I am new to the C language, I am wondering which method you would think would be most beneficial and easy to code and easy to debug, etc. if there were a problem, and of course if anyone has an example, that would be helpful as well.
Thanks very much.
Well option 1 is the easiest to code/debug, since what you need is already in memory in a handy form for searching (an array).
It's only downside is whether you have the memory - if it happens to be a very large file.
Both would be good exercises for the student :)