Thread: Table Lookup Processing

  1. #1
    Registered User
    Join Date
    Aug 2001

    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:

    Option 1:
    Read the second file (translations file) into a two dimensional array of structures, which contain multiple occurances of the following:

    char code[3];
    char description[20]

    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.

    Option 2:

    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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick log lookup table
    By R.Stiltskin in forum C++ Programming
    Replies: 19
    Last Post: 12-04-2008, 12:39 PM
  2. search file for values in lookup table
    By sixstringsgaret in forum C Programming
    Replies: 12
    Last Post: 03-04-2008, 04:23 PM
  3. using a shared lookup table
    By zxcv in forum C Programming
    Replies: 1
    Last Post: 02-21-2008, 12:10 AM
  4. Lookup table with different spacing between entries
    By Boksha in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2008, 02:40 PM
  5. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM