Table Lookup Processing

This is a discussion on Table Lookup Processing within the C Programming forums, part of the General Programming Boards category; I am in need of a way to read two files as input, and produce an output file. One file ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    20

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 11:39 AM
  2. search file for values in lookup table
    By sixstringsgaret in forum C Programming
    Replies: 12
    Last Post: 03-04-2008, 03:23 PM
  3. using a shared lookup table
    By zxcv in forum C Programming
    Replies: 1
    Last Post: 02-20-2008, 11:10 PM
  4. Lookup table with different spacing between entries
    By Boksha in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2008, 01:40 PM
  5. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21